Counter

    [파이썬] collections 모듈 - Counter (사용빈도 확인)

    데이터의 개수를 셀 때 유용한 파이썬의 collections 모듈의 Counter 클래스 사용법을 알아보겠습니다. 알파벳 사용빈도 확인 from collections import Counter Counter('hello world') 실행 결과 Counter({'l': 3, 'o': 2, 'h': 1, 'e': 1, ' ': 1, 'w': 1, 'r': 1, 'd': 1}) 다음으로는 most_common() 함수에 대해 설명하겠습니다. most_common()함수는 Counter()에서 가장 빈도수가 높은 순으로 표시 해 주는 함수입니다. 인자값으로 숫자를 입력하면 숫자번째까지의 빈도수를 표시합니다. from collections import Counter data="hello world" result..