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

    python collections.Counter的计数

    小妮浅浅小妮浅浅2021-05-17 09:34:11原创1520

    1、说明

    Counter 类型中的计数器还支持负值。

    通过简单的 +/- 作为 Counter 类型对象的前缀,就可以实现正负计数过滤。Python 的这一设计很优雅。

    2、实例

    c = collections.Counter(x=1, y=-1)
    logging.info('+c -> %s', +c)
    logging.info('-c -> %s', -c)

    运行结果:

    INFO - +c -> Counter({'x': 1})
    INFO - -c -> Counter({'y': 1})

    以上就是python collections.Counter计数的使用,希望能对大家有所帮助。更多Python学习指路:python基础教程

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

    专题推荐:python collectionscounter
    品易云
    上一篇:python中collections.Counter是什么? 下一篇:python中使用OpenCV画线

    相关文章推荐

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

    全部评论我要评论

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

  • 取消发布评论
  • 

    Python学习网