Python counter

from collections import Counter

cnt = Counter()
cnt["foo"] += 1
cnt["bar"] += 2
print(dict(cnt))  # {'foo': 1, 'bar': 2}