how to retrieve the related list by using python

Assume I have this:

[
  {"name": "Tom", "age": 10},
  {"name": "Mark", "age": 5},
  {"name": "Pam", "age": 7}
]

and by searching name, I want to retrieve the related list: ["Tom", "Mark", "Pam"]

How to achieve this ?

Answer

You can use .get() method to get the particular key’s value. Alternatively, you can also, do j['name']

l1=[
  {"name": "Tom", "age": 10},
  {"name": "Mark", "age": 5},
  {"name": "Pam", "age": 7}
]
l2=[j.get("name") for j in l1]