知行编程网知行编程网  2022-12-30 11:30 知行编程网 隐藏边栏  1 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python中collections.Counter是什么?的相关知识,希望可以帮到处于编程学习途中的小伙伴

什么是 collections.Counter 在 python 中?


1、说明

可用于计算可散列对象,或作为多集 - 多集是其元素可以出现多次 1 的集合。

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


2、实例

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中co

llections.Counter的介绍,希望能对大家有所帮助。

更多Python学习指路:


本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享