Answers for "access nested set with array params python"

0

access nested set with array params python

def nested_set(dic, keys, value):
    for key in keys[:-1]:
        dic = dic.setdefault(key, {})
    dic[keys[-1]] = value
    
>>> d = {}
>>> nested_set(d, ['person', 'address', 'city'], 'New York')
>>> d
{'person': {'address': {'city': 'New York'}}}

from : 
https://stackoverflow.com/questions/13687924/setting-a-value-in-a-nested-python-dictionary-given-a-list-of-indices-and-value
Posted by: Guest on February-02-2021

Code answers related to "access nested set with array params python"

Python Answers by Framework

Browse Popular Code Answers by Language