0

I have two nested dictionaries that look like this:

d1 = {'a': {'b': {'c': 1}}}
d2 = {'a': {'b': {'d': 2}}}

and I need to merge them by nested keys, adding the nested elements. the result should be:

d = {'a': {'b': {'c': 1, 'd': 2}}}

I'm trying to build a recursive function, but maybe there is a better way available

any suggestion? thanks

ilmatte
  • 51
  • 3
  • The duplicate answers I linked should answer your question, it also address what can be done if a key is duplicated in one of the leaves of your dictionaries. Let me know if you feel this does not properly solve your issue. – Olivier Melançon Jul 04 '23 at 16:49

0 Answers0