목록collections (1)
minimimi
[Python] Collections 모듈: counter, most_common
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..
프로그래밍 공부/Python
2022. 3. 19. 20:30