List of Dictionary Values match on Plain Dictionary; update the value

I have two variables one is a list of dictionaries and another one is a plane dictionary

  1. we have to match the list of dictionaries “id” values with the plain dictionary key.
  2. when the match is found update the list of dictionary name keys values based on plain dictionary values.

below are the references

lst1 = [{"id":"01","name":"michel","age":"30"},{"id":"02","name":"oliever","age":"29"},{"id":"04","name":"james","age":"28"}] #list of dictionaries

lst2 = {"01":"Surendra","02":"Ravi","03":"Ramu"}#Dictionary

when we print(lst1) the output will be like this

 O/p:[{'id': '01', 'name': 'Surendra', 'age': '30'}, {'id': '02', 'name': 'Ravi', 'age': '29'}, {'id': '04', 'name': 'james', 'age': '28'}]

Answer

lst1 = [
        {"id": "01", "name": "michel", "age": "30"},
        {"id": "04", "name": "oliever", "age": "29"},
        {"id": "03", "name": "james", "age": "28"}
        ]
lst2 = {"01": "Surendra", "02": "Ravi", "03": "Ramu"}

for l in lst1:
    if l['id'] in lst2:
        l['name'] = lst2[l['id']]

print(lst1)

[{'id': '01', 'name': 'Surendra', 'age': '30'}, {'id': '04', 'name': 'oliever', 'age': '29'},{'id': '03', 'name': 'Ramu', 'age': '28'}]