I am using Python 3.5 and I have a problem assigning values to a dictionary key. The structure of my dictionary looks like this:
dict_var = {'file':
{'index':
{'flag':
{'flag_key': 'False'},
'attr':
{'attr_key': 'attr_val'},
'path':
{'path_key': 'path_val'},
}
}
}
I get the KeyError: 1, if I change the nested key 'index' like this:
dict_var['file']['1']['flag'] = 'some value'
dict_var['file']['2']['flag'] = 'some value'
dict_var['file']['3']['flag'] = 'some value'
dict_var['file']['4']['flag'] = 'some value'
Or if I try to change the nested key 'flag':
dict_var['file']['index']['flag_2']['flag_key'] = 'some value'
Is there a way to assign a new name to a nested key, but keep the structure of the following sub keys and values, like in my example?