(1)从Collections集合模块中引入集合类Counter
(2)Counter(a)可以打印出数组a中每个元素出现的次数
(3)Counter(a).most_common(n)可以打印出数组中 出现次数最多的元素。参数n表示的含义是:输出几个出现次数最多的元素。
a = [1,4,2,3,2,3,4,2]
from collections import Counter
print(Counter(a))
print(Counter(a).most_common(2)) #
python中统计计数的几种方法和Counter的介绍