특정 index로 리스트 정렬하는 방법 -파이썬
sorted() 활용하기 student_tuples = [ ... ['john', 'A', 15], ... ['jane', 'B', 12], ... ['dave', 'B', 10], ... ] >>> sorted(student_tuples, key=lambda student: student[2]) //index 2로 정렬 [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
[프로그래머스 Level1] 둘만의 암호
틀린 풀이 def solution(s, skip, index): alpa = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] new = '' for i in skip: if i in alpa: alpa.remove(i) for i in s: if i in alpa: k = alpa.index(i) k += index if k > 26-len(skip): k - (26-len(skip)) new += alpa[k] else: new += alpa[k] return new if문의 계산으로 인해서 계산과정이 하나 더 생겨서 ..
파이썬 약수 구하기
약수를 구하는 방법 1. n의 약수를 구하는 상황이라면 1부터 n보다 작거나 같은 수로 n을 나눈다. 나누어 떨어진다면 이는 n의 약수에 해당하게 된다. ex) 24 -> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 n = int(input()) divisor_list = [] for i in range(1, n+1): if n % i == 0: divisor_list.append(i) 단점 : 이러면 n이 큰 수라면 시간 복잡도가 높아진다. O(N) 약수를 구하는 방법(시간 복잡도 단축) 2. #코드 Tab 에러가 있음..;;; n = int(input()) diviors_list = [] fo..