A = {'a': 1, 'b': 2, 'c': 3}
B = {'b': 3, 'c': 4, 'd': 5}
c = {x: (A.get(x, 0) + B.get(x, 0)) for x in set(A).union(B)}
print(c)
Is there any pythonic way to combine two dicts (adding values for keys that appear in both)?