Skip to content
Advertisement

How to append lists in nested dictionary in Python

I have 2 nested dictionaries:

JavaScript

And I want to append these 2 dictionaries,the output should looks like this:

JavaScript

First tried:

JavaScript

And out put is none.

Then I tired:

JavaScript

Out put is still none!

Advertisement

Answer

You can use recursion with collections.defaultdict:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement