python中collections.Counter是什么?

627次阅读
没有评论

python中collections.Counter是什么?

collections.Counter说明

可以用来给可散列的对象计数,或者是当成多重集合来使用 —— 多重集合就是集合里的元素可以出现多次1。

类似于其它编程语言中的 bags 或者 multisets2。

collections.Counter实例

counter = collections.Counter(['生物', '印记', '考古学家', '生物', '枣', '印记'])
logging.info('counter -> %s', counter)
 
counter.update(['化石', '果实', '枣', '生物'])
logging.info('counter -> %s', counter)
 
most = counter.most_common(2)
logging.info('most -> %s', most)

以上就是python中collections.Counter的介绍,希望能对大家有所帮助。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-05-03发表,共计409字。
新手QQ群:570568346,欢迎进群讨论 Python51学习