Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

PREVIOUS NEXT
Code Example
Python :: clear multiprocessing queue python 
Python :: python sleep 5 seconds 
Python :: center button in tkinter 
Python :: degree symbol in python 
Python :: inverse matrix python 
Python :: python count number of zeros in a column 
Python :: get longest shortest word in list python 
Python :: how to import login required in django 
Python :: folium anaconda 
Python :: python auto clicker 
Python :: python pie chart 
Python :: Python Current time using datetime object 
Python :: get date and time in python 
Python :: label encoder python 
Python :: python set cwd to file location 
Python :: pandas replace nonetype with empty string 
Python :: counter in django template 
Python :: how to save a png seaborn pandas 
Python :: bee movie script 
Python :: dislike_count 
Python :: python ping ip address 
Python :: install googlesearch for python 
Python :: user agents list 
Python :: thousands separator python 
Python :: pylint no name in module cv2 
Python :: convert epoch to date time in python 
Python :: how to plot roc curve in python 
Python :: python install required packages 
Python :: python write array to file 
Python :: discord.py commands not working 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =