1def nested_set(dic, keys, value):
2 for key in keys[:-1]:
3 dic = dic.setdefault(key, {})
4 dic[keys[-1]] = value
5
6>>> d = {}
7>>> nested_set(d, ['person', 'address', 'city'], 'New York')
8>>> d
9{'person': {'address': {'city': 'New York'}}}
10
11from :
12https://stackoverflow.com/questions/13687924/setting-a-value-in-a-nested-python-dictionary-given-a-list-of-indices-and-value