我有一个方法,需要能够一次添加多个嵌套字典。
例如:
mydict = {}
mydict['subdict']['subdict2'] = {'this': 'is what i want'}
我该怎么做?
from collections import defaultdict
mydict = defaultdict(dict)
mydict['subdict']['subdict2'] = {'this': 'is what i want'}
我会在字典内创建一个空字典,以便嵌套字典。
这里;
my_dict = {}
my_dict["nested_item_1"] = {}
my_dict["nested_item_1"] = your_variable_here