A Pythonic Way to Combine Two Dicts

For example I have two dicts:

dict_a = {'a': 1, 'b': 2, 'c': 3}
dict_b = {'b': 3, 'c': 4, 'd': 5}

I need a pythonic way of 'combining' two dicts such that the result is:

{'a': 1, 'b': 5, 'c': 7, 'd': 5}

That is to say: if a key appears in both dicts, add their values, if it appears in only one dict, keep its value.

Use collections.Counter:

from collections import Counter
a = Counter({'a':1, 'b':2, 'c':3})
b = Counter({'b':3, 'c':4, 'd':5})
c = a + b # c = Counter({'c': 7, 'b': 5, 'd': 5, 'a': 1})

Counters are basically a subclass of dict, so you can still do everything else with them you'd normally do with that type, such as iterate over their keys and values.