PL/Python

[Python] array에서 최빈값 구하기

SweetDev 2021. 11. 28. 13:42

collection의 Counter를 활용하여 빈도수를 구한다.

 

튜플 형태로, 0에는 value 1에는 빈도(count)가 들어온다.

cnt = Counter(numbers).most_common(2) # 가장 개수가 많은 두개의 데이터 리턴함




출처: https://somjang.tistory.com/entry/BaekJoon-2108번-통계학-Python [솜씨좋은장씨]