字典中的最高值

字典中的最高值,第1张

字典中的最高值

用途

collections.Counter

>>> d = Counter({'a': 2, 'and': 23, 'this': 14, 'only.': 21, 'is': 2, 'work': 2, 'will': 2, 'as': 2, 'test': 4})>>> d.most_common()[('and', 23), ('only.', 21), ('this', 14), ('test', 4), ('a', 2), ('is', 2), ('work', 2), ('will', 2), ('as', 2)]>>> for k, v in d.most_common(3):...     print '%s: %i' % (k, v)... and: 23only.: 21this: 14

计数器对象还具有其他各种优点,例如,使收集计数变得非常简单。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5644037.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存