Extract dict value from list of dict in python

Chencheng Liu

I have a list of dicts like this:

[{'name': 'John', 'age': 25}, {'name': 'Matt', 'age': 35} , {'name': 'Peter', 'age': 40}]

How can I get the name for those whose age is between 20-30 ?

Many thanks for your help.

0x5453

Something like this should do it:

list_of_dicts = [{'name': 'John', 'age': 25}, {'name': 'Matt', 'age': 35} , {'name': 'Peter', 'age': 40}]
names = [d['name'] for d in list_of_dicts if 20 <= d['age'] <= 30]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract values based on keys from a list of `dict` objects in Python

How to extract specific values from a list in a dict in python?

Python : List of dict, if exists increment a dict value, if not append a new dict

How to extract value from a dict in a string - Pandas / Python

Python extend dict value to list

Sort a list by value of a dict python

python the list in dict extend value

Extract values from a dict made of a list made of another dict

Is there any way in python to get a specific list of value from list of dict?

How to append key value pair to an existing list of dict from another list of dict based on matching Key in Python

extract image from a list like dict

Extract value from dict in pandas dataframe

Adjacency list from Python dict

Tuple list from dict in Python

Get a dict from a python list

Create a new list of dict, from a dict with a key that has a list value

How to initialize a dict with keys from a list and empty value in Python?

Distinguishing Nested Dict Assignment from List Value Access in a Python Dictionary

Python: how to sum all value with different name from dict in list

Python - Sort a list of dics by value of dict`s dict value

Return A Value by searching for another value in a list of dict of dict in Python

Extract value in dict

how to get the list value from list of dict

From list of dict to single dict using values as key/value pairs

Delete key:value pair from dict in list in nested dict

Python append value from dict to existing dict with two value if there is a match

Extract dict from string

golang defining dict like python with and appending value to list in dict

Extract information from html list to pandas df/list/dict (python 3.0)