Skip to content
Advertisement

How to fill nested dict when you only have a list of key, value for the final layers?

I have a nested dict of the folling form:

JavaScript

And a flat dict with only the values in the final layer:

JavaScript

My expected output after filling the values in the first dict would be:

JavaScript

How should I approach this?

Advertisement

Answer

I hope I’ve understood your question correctly. You can use recursion to replace the values of keys in-place:

JavaScript

Prints:

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