【发布时间】:2015-07-21 08:57:14
【问题描述】:
据我了解,我知道何时调用 Counter 来隐藏字典。此 dict 包含的键值为零将消失。
from collections import Counter
a = {"a": 1, "b": 5, "d": 0}
b = {"b": 1, "c": 2}
print Counter(a) + Counter(b)
如果我想保留我的钥匙,怎么办?
这是我的预期结果:
Counter({'b': 6, 'c': 2, 'a': 1, 'd': 0})
【问题讨论】:
标签: python python-2.7 dictionary counter