목록프로그래밍 공부/Python (2)
minimimi
counter 함수 collections.Counter(iterable): return dict 예제코드 import collections a = [1,2,3,4,1,1,2,3,4] b = [1,2,3,4,1,1,5,6,7] print(collections.Counter(a),'\n', collections.Counter(b)) print(type(collections.Counter(a))) 결과 >>> Counter({1: 3, 2: 2, 3: 2, 4: 2}) Counter({1: 3, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1}) counter 연산 +, -, &(교집합), |(교집합) 연산 가능 예제코드 import collections a = [1,2,3,4,1..
1. 순열 permutations(Iterable, r) # 순열 from itertools import permutations for i in permutations([1,2,3,4], 2): print(i, end=" ") # (1, 2) (1, 3) (1, 4) (2, 1) (2, 3) (2, 4) (3, 1) (3, 2) (3, 4) (4, 1) (4, 2) (4, 3) 2. 조합 combinations(Iterable, r) # 조합 from itertools import combinations for i in combinations([1,2,3,4], 2): print(i, end=" ") # (1, 2) (1, 3) (1, 4) (2, 3) (2, 4) (3, 4) 3. 중복순열 produc..