I have four nested dictionaries:
a = {
1: {'a': 123, 'b': 222, 'c': 888},
2: {'a': 333, 'b': 555, 'c': 345}}
b = {
1: {'d': 456, 'e': 333, 'f': 333},
2: {'d': 555, 'e': 233, 'f': 433}}
c = {
1: {'g': 789, 'h': 444, 'i': 999},
2: {'g': 456, 'h': 333, 'i': 333}}
d = {
1: {'j': 111, 'k': 555, 'l': 222},
2: {'j': 456, 'k': 333, 'l': 333, 'm': 555}}
I want to concatenate/merge them into a new dictionary and group by the main key. The desired output is:
result = {
1: {'a': 123, 'b': 222, 'c': 888, 'd': 456, 'e': 333, 'f': 333, 'g': 789, 'h': 444, 'i': 999, 'j': 111, 'k': 555, 'l': 222},
2: {'a': 333, 'b': 555, 'c': 345, 'd': 555, 'e': 233, 'f': 433, 'g': 456, 'h': 333, 'i': 333, 'j': 456, 'k': 333, 'l': 333, 'm': 555}}
Each dictionary (a,b,c,d) has exactly 200 main keys (1 to 200) - I've only shown 2 entries each. There are no duplicate sub keys, but there are sometimes more subkeys in one than another (see "d").
I realize there are numerous very similar questions on StackOverflow, but the ones I found seem to involve something else (tuples, lists, combining only two dictionaries, etc.) and I have not been able to adapt any to my situation. An unsuccessful attempt (based on a similar question) that seemed logical given what I want the result to be:
result = {key: a[key] + b[key] + c[key] + d[key] for key in a}