Python Practice › Dictionary Programs › Program 82
Values of one key from many dicts
Write a Python program to get the values of a key from a list of dictionaries.
Input
[{"name": "jos", "age": 30}, {"name": "david", "age": 25}, {"name": "virat", "age": 32}], key "age"Output
[30, 25, 32]
Approach
- A comprehension.
Solution
data = [{"name": "jos", "age": 30}, {"name": "david", "age": 25}, {"name": "virat", "age": 32}]print([d["age"] for d in data])Output
[30, 25, 32]
Learn the concept
New to this topic? Read the lesson, then come back.