如何添加或增加Python Counter类的单个项目

如何添加或增加Python Counter类的单个项目,第1张

如何添加增加Python Counter类的单个项目

好吧,您真的不需要使用

Counter
计数方法,对吗?有一个
+=
运算符,它也可以与Counter一起使用。

c = Counter()for item in something:    if item.has_some_property:        c[item.property] += 1    elif item.has_some_other_property:        c[item.other_property] += 1    elif item.has_some.third_property:        c[item.third_property] += 1


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5617923.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存