📜  python 查找最常出现的元素 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:34.986000             🧑  作者: Mango

代码示例1
from collections import Counter

a = [1936, 2401, 2916, 4761, 9216, 9216, 9604, 9801] 

c = Counter(a)

print(c.most_common(1)) # the one most common element... 2 would mean the 2 most common
[(9216, 2)] # a set containing the element, and it's count in 'a'