[백준] 2108 통계학 Python Counter모듈
·
Algorithm/백준
#2108 통계학 1. from collections import Counter 모듈 사용 - Counter()를 사용하면 다음과 같이 빈도수와 리스트를 dictionary 형태로 저장해준다. - most_common()을 사용하면 빈도수로 정렬하고 dictionary를 list[tuple()] 형태로 저장해준다. from collections import Counter colors = Counter(['blue', 'green', 'red', 'blue','red','blue']) print(colors) # Counter({'blue': 3, 'red': 2, 'green': 1}) print(colors.most_common()) # [('red', 3), ('blue', 2), ('green', ..