Create a nested path
Input
update_nested({}, ['x', 'y', 'z'], 1)
Output
{'x': {'y': {'z': 1}}}
Intermediate dicts are created to set z to 1.
Full lesson preview
Set a value deep inside a nested dictionary, creating intermediate dicts as needed.
Problem statement
Task
Examples
Input
update_nested({}, ['x', 'y', 'z'], 1)
Output
{'x': {'y': {'z': 1}}}
Intermediate dicts are created to set z to 1.
Input format
Output format
Constraints
Samples
Input
update_nested({'a': 1}, ['a', 'b'], 2)
Output
{'a': {'b': 2}}
Existing non-dict value for 'a' is replaced with a dict to set 'b'.