I have a list of dictionaries:
original_dict = [{'1': 'chair', '20': 'carpet'}, {'1': 'sofa', '23': 'tv'}]
My goal is to re-assign the keys so that they match the values in this dictionary:
new_keys = {'1': 'seating', '20': 'flooring', '23': 'electronics}
The result I want is this:
[{'seating': 'chair', 'flooring': 'carpet'}, {'seating': 'sofa', 'electronics': 'tv}]
I tried the following method:
new_dicts = [{**keys, **new_keys} for keys in original_dict]
and ended up with:
[{'1': 'seating', '20': 'flooring', '23': 'electronics'}, {'1': 'seating', '23': 'electronics', '20': 'flooring'}]
which swapped the values instead of the keys and then represented every key value pair in each of the dictionaries inside the list. Using nested for loops is probably easier to get what I want, does anyone have a method that achieves my expected results?