python
Get all values by key name from a list of dictionaries Python
If you want to get all values by using the key name from a list of dictionaries then you can use the below code for that.
users = [
{ "name": "John Deo", "username": "john01" },
{ "name": "Stephen Hawk", "username": "stephen" },
{ "name": "Rick Grimes", "username": "rick21" }
]
names = [d["name"] for d in fruits] #returns list
print(names)
#prints - ["John Deo", "Stephen Hawk", "Rick Grimes"]
names_comma_seperated = ','.join( [d["title"] for d in data['current']] )
print(names_comma_seperated)
#prints - John Deo,Stephen Hawk,Rick Grimes
Was this helpful?
Similar Posts
- [Python] Using inspect.stack() to get module name, path, function name
- [Python] Using comprehension expression to convert list of dictionaries to nested dictionary
- Convert pandas DataFrame to List of dictionaries python
- Convert JSON string to Python collections - like list, dictionaries
- Column name as alias name SQLAlchemy
- Python collection - Dictionaries in python
- Convert all string values in a list to integers using python