I have two 2D python dictionaries, and I want to get a single 2D dictionary where the keys are the union of the first two dictionaries' keys and the values a concatenation of the 1d dictionary. In case of duplicate keys in the 1D dictionaries, I would like to have the sum of their values.
So, supposing that I've :
dict1 = { 1: {2: 0.1, 3: 0.3, 4: 0.4} ,
2 :{1: 0.2, 3: 0.3, 4: 0.5} }
dict2 = { 2: {1: 0.1, 3: 0.8, 5: 0.4} ,
3 :{1: 0.2, 2: 0.8, 4: 0.5} }
what I expect to have is:
merged_dict = { 1: {2: 0.1, 3: 0.3, 4: 0.4} ,
2 :{1: 0.3, 3: 1.1, 4: 0.5 , 5: 0.4} ,
3: {1: 0.2, 2: 0.8, 4: 0.5} }
I'm currently using python 3.2.3