Python统计列表中重复次数最多的前N个元素
时间:2019-03-04 10:45:27
收藏:0
阅读:437
from collections import Counter
a = [1, 1, 7, 3, 6, 2, 5, 4, 4, 3, 9, 4, 4, 1]
#统计列表中重复次数最多的前N个元素
N = 3
print(Counter(a).most_common(N))
#输出是[(4, 4), (1, 3), (3, 2)]
原文:https://www.cnblogs.com/zpf1092841490/p/10469184.html
评论(0)