Right now i have this:
A={0:[{1:2},{2:3}],
1:[{4:5},{5:6}]}
And I want to change this dictionary to the following:
A={0:{1:2,2:3},
1:{4:5,5:6}}
Is this possible?
Right now i have this:
A={0:[{1:2},{2:3}],
1:[{4:5},{5:6}]}
And I want to change this dictionary to the following:
A={0:{1:2,2:3},
1:{4:5,5:6}}
Is this possible?
Try doing this: Iterate over the elements int the list and merge them into temp_dict
. assign temp_dict
to the key of the original dictionary.
A={0:[{1:2},{2:3}],
1:[{4:5},{5:6}]}
for k,v in A.items():
temp_dict={}
for elem in v:
for k2,v2 in elem.items():
temp_dict[k2] = v2
A[k] = temp_dict
print A
# prints {0: {1: 2, 2: 3}, 1: {4: 5, 5: 6}}