In a list of non-identical dictionaries, two different Key names are randomly used to hold the same kind of value. For example "animal" and "beast" but all should just be "animal":
list = [{'beast': 'dog', 'age': 3, 'weather': 'cold'},
{'animal': 'cat', 'age': 2, 'food': 'catnip'},
{'animal': 'bird', 'age': 15, 'cage': 'no'}]
I need to replace key['beast'] with key['animal'].
I have tried the following but only works if all the relevant Keys are "beast" which then can be renamed to "animal":
for pet in list:
pet['animal'] = pet['beast']
del pet['beast']
The same applies for another way:
for pet in list:
pet['animal'] = pet.pop('beast')
I'd like the output to become:
[{'age': 3, 'weather': 'cold', '**animal**': 'dog'},
{'age': 2, 'food': 'catnip', '**animal**': 'cat'},
{'age': 15, 'cage': 'no', '**animal**': 'bird'}]