
统计 字典的个数
di = {
"a":20,
"b":88,
"c":99,
"d":9
}
from collections import Counter
counts = Counter(di)
for i in counts:
print(i,counts[i])
print(counts.most_common(3))
本文介绍了一种使用Python的collections模块中的Counter类来统计字典中元素的方法。通过实例演示了如何遍历字典并统计各元素出现的次数,以及如何获取出现频率最高的前几个元素。

统计 字典的个数
di = {
"a":20,
"b":88,
"c":99,
"d":9
}
from collections import Counter
counts = Counter(di)
for i in counts:
print(i,counts[i])
print(counts.most_common(3))
7900
9117

被折叠的 条评论
为什么被折叠?
