I need to combine two dictionaries in python in such a way that values using the same keyS are added. I already found this answer based on collections.Counter, but this does not work on nested dictionaries.
One example:
A = {0: {1: 8, 2: 4}, 1: {0: 8, 2: 3}, 2: {0: 3, 1: 7}}
B = {0: {1: 1, 2: 0}, 1: {0: 1, 2: 5}, 2: {0: 4, 1: 10}}
Result should be:
combine(A,B) = {0: {1: 9, 2: 4}, 1: {0: 9, 2: 8}, 2: {0: 7, 1: 17}}
There are always two level of nesting and the key sets are always identical. If A[x][y] exists, you can assume that B[x][y] also exists, also the other way around. Both dicts are initialized with 0 entries. Thanks in advance!