I have a list of dictionaries as input :
[{
Acc: "ABC IN."
CFC: "XC"
CC: "1001"
SC: "DER"
Config Path: "..//"
File Path: "..//"
}]
I wanted to convert it into a template nested dictionary the only catch being the key of the nested dictionary is also derived from the above dictionary itself Desired output
{'XC': {'1001': {'DER': {'Config Path': '..//' ,'File Path' : "..//" }}}}
The input can be multiple and whenever a new CFC , CC or SC arrives a new key is generated on the same level as that of the previous .
I tried dynamically generating key but it was showing key not found error
main_dict = {}
for item in main_dict_list:
main_dict[item['CFC']][item['CC']][item['SC']]['Config Path']=item['Config Path']
main_dict[item['CFC']][item['CC']][item['SC']]['File Path']=item['File Path']
I also tried to follow hierarchy to input key-value from inside the dictionary
main_dict = {}
for item in main_dict_list:
temp={}
temp['model_config_path']=item['Config Path']
temp['model_config_path']=item['File Path']
temp1 = {}
temp1[item['SC']] = temp
temp2 ={}
temp2[item['CC']] =temp1
main_dict[item['CFC']] =temp2
it also doesn't seem to work properly. I am not able to think about any other solution