如果python中的列表中有键,如何更新字典中键的值?
# data is dictionary containing multi-level key value
key_list = ['key1','key2','key3']
print(data[key1][key2][key3])
from flatten_dict import flatten
from flatten_dict import unflatten
# Flattern the data dict
flatten_data = flatten(data)
key_tuple = tuple(key_list)
flatten_data[key_tuple]= newValue # Add your new value here
# Unflatten the data dict
data = unflatten(flatten_data)