Answers for "python get item in list with dict value"

1

python find dict in list of dict by id

>>> dicts = [
     { "name": "Tom", "age": 10 },
     { "name": "Mark", "age": 5 },
     { "name": "Pam", "age": 7 },
     { "name": "Dick", "age": 12 }
 ]
>>> next(item for item in dicts if item["name"] == "Pam")
{'age': 7, 'name': 'Pam'}

# WITH DEFAULT VALUE TO None if None
next((item for item in dicts if item["name"] == "pam"), None)
Posted by: Guest on March-10-2021
7

python get dict values as list

food_list=list(data.values())
print(food_list)
Posted by: Guest on February-29-2020

Code answers related to "python get item in list with dict value"

Python Answers by Framework

Browse Popular Code Answers by Language