I have two lists as shown below. I want to update the new list using the old list. The criteria to update the new list are matching values for name in old list. What is the best way to do it?
Input
old_list = [{'age': 35, 'name': 'james'}, {'age': 42, 'name': 'bob'}]
new_list = [{'name': 'peter'}, {'name': 'james'}, {'age': 50, 'name': 'bob'}]
Expected Output
[{'name': 'peter'}, {'age': 35, 'name': 'james'}, {'age': 42, 'name': 'bob'}]
Edit: Adding my solution
One solution that I know to solve this using multiple loops and if conditions. It is not the compete solution as I need to handle multiple scenarios like where key is not present etc.
for x in new_col_list:
for y in old_col_list:
if x['name'] == y['name']:
x['age'] = y['age']
continue
print new_col_list