I have a dict like this:
d={
'McAfee': {'DatDate': '123','DatVersion': '456'},
'AntiVirus': {'AVName': ['Mac Defender', 'Windows Defender'],'AVVersion': ['262144', '393472']}
}
Now I want to change the key of d and change the value's key of d too according to this mapping:
mapping_table = {"McAfee":'Mc_table','AntiVirus':'An_table'}
mapping_coulmn = {'DatDate':"Dc_column",'AVName':'Av_column','DatVersion':'Da_column','AVVersion':'AVV_column'}
The output should like:
d={
'Mc_table': {'Dc_column': '123','Da_column': '456'},
'An_table': {'Av_column': ['Mac Defender', 'Windows Defender'],'AVV_column': ['262144', '393472']}
}
What I tired is:
for key in d:
if key in mapping_table:
new_key = mapping_table[key]
d1[new_key]=d.pop(key)
print(d)
It returns an error:
RuntimeError: dictionary keys changed during iteration
Any friend can help?Thank you so much!