Answers for "find a value from list of dict python"

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
1

dict get list of values

list(d.values())
Posted by: Guest on June-12-2020
1

python get elements from list of dictionaries

dct = {"Id": 1, "Name": "Suresh", "Location": "Hyderabad"}
uid = dct["Id"]
name = dct["Name"]
location = dct["Location"]
print("Id = {}, Name = {}, Location = {}".format(uid, name, location))
Posted by: Guest on May-30-2021

Code answers related to "find a value from list of dict python"

Python Answers by Framework

Browse Popular Code Answers by Language