I have several dictionaries that I would like to combine, so if the key is in several dictionaries, the values ββare added together. For instance:
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 looked at defaultdict and tried to come up with something. I am using Python 2.6.
source share