파이썬 - 리스트 원소 개수 구하기/collections모듈의 Counter클래스 활용 예제
collections모듈의 Counter클래스 Counter클래스 활용 from collections import Counter arr=[1,2,3,3,6,2,1,4,4,4,5,5,5] cnt = Counter(arr) print("Counter(arr) =",cnt) #Counter(arr) = Counter({4: 3, 5: 3, 1: 2, 2: 2, 3: 2, 6: 1}) cnt = Counter(arr).most_common() print("Counter(arr).most_common() =",cnt) #Counter(arr).most_common() = [(4, 3), (5, 3), (1, 2), (2, 2), (3, 2), (6, 1)] #Counter(리스트).most_common()은 리스..
2021. 6. 2.