Skip to content
Advertisement

Access a deeply nested dictionary and multiply values

I have this nested dictionary:

JavaScript

I need to access the ‘w’ values and make them multiply by 3. What I’ve tried is:

JavaScript

It doesn’t work, and I’ve tried other ways and it doesn’t work as well. Any tips?

EDIT: Wrong dictionary, edited it

Advertisement

Answer

You could use a recursive function that modifies “w” values:

JavaScript

Output:

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