【发布时间】:2021-09-06 02:58:35
【问题描述】:
在python中有什么更好的方法来做到这一点 当前 = {}
if key in current:
current[key] += 1
else:
current[key] = 1
感谢您的帮助
【问题讨论】:
-
你想做什么?
-
张贴minimal reproducible example 并查找collections.Counter
-
如何更好?这是可读且高效的。
-
这能回答你的问题吗? Frequency mapping with dictionary in Python
-
你可以使用
defaultdict(int)或current.get(key, 0)+1
标签: python python-3.x dictionary