From the source;
def __add__(self, other):
'''Add counts from two counters.
>>> Counter('abbb') + Counter('bcc')
Counter({'b': 4, 'c': 2, 'a': 1})
'''
if not isinstance(other, Counter):
return NotImplemented
result = Counter()
for elem, count in self.items():
newcount = count + other[elem]
if newcount > 0:
result[elem] = newcount
for elem, count in other.items():
if elem not in self and count > 0:
result[elem] = count
return result
It seems that Counter implemented as removing keys which sums to zero non-positive keys. Since default value is zero, and the source has also zero, the resulting dict doesn't contains that key.
Maybe you can get the same behavior with update:
a.update(b)
seems to do what you want. Probably slower tho, a hand-made implementation of the __add__
method would be much faster.