I have several dictionaries which I'd like to combine such that if a key is in multiple dictionaries the values are added together. For example:
d1 = {1: 10, 2: 20, 3: 30}
d2 = {1: 1, 2: 2, 3: 3}
d3 = {0: 0}
merged = {1: 11, 2: 22, 3: 33, 0: 0}
What is the best way to do this in Python? I was looking at defaultdict and trying to come up with something. I'm using Python 2.6.