python collections.Counter的计数
发布时间:2024-08-27 13:39:20

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电脑。
