您现在的位置是:课程教程文章

python中collections.Counter是什么?

2023-12-14 22:11课程教程文章 人已围观

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中collections.Counter的介绍,希望能对大家有所帮助。更多Python学习指路:python基础教程

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

课程教程:python中collections.Counter是什么?

上一篇:python collections.Counter的计数

下一篇:没有了

站点信息

  • 文章统计篇文章