I have a list of dictionaries like below:
my_dict_1 = {'a': 1, 'b': 2, 'c': 3}
my_dict_2 = {'a': 10, 'b': 20, 'c': 30}
original_list = [my_dict_1, my_dict_2]
I am trying to iterate over this list and change one of the keys of the original dictionaries while keeping the order of the keys the same as the original. So the resulting dictionaries will be like this:
my_dict_1 = {'a': 1, 'New': 2, 'c': 3}
my_dict_2 = {'a': 10, 'New': 20, 'c': 30}
Can it be done in a single for loop ? So far tried this:
for i in [my_dict_1, my_dict_2]:
i['NEW'] = i.pop('b')
print(my_dict_1)
output: {'a': 1, 'c': 3, 'NEW': 2}
The result does not keep the original order.