• 技术文章 >Python技术 >Python基础教程

    python中collections.Counter是什么?

    小妮浅浅小妮浅浅2021-05-17 09:32:44原创2205

    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 collectionscounter
    品易云
    上一篇:python中如何安装pyenv 下一篇:python collections.Counter的计数

    相关文章推荐

    • python中FileNotFoundError的异常• input在python中的使用注意• python中input()转换字符串• python中ssl认证是什么?• python函数装饰器的应用过程• python中如何安装pyenv

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网