
用途
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计数器对象还具有其他各种优点,例如,使收集计数变得非常简单。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)