Python Practice › Dictionary Programs › Program 83
Keys with a given value
Write a Python program to find all keys that have a given value.
Input
{"a": 19, "b": 20, "c": 21, "d": 20}, value 20Output
['b', 'd']
Approach
- Filter
items().
Solution
d = {"a": 19, "b": 20, "c": 21, "d": 20}print([k for k, v in d.items() if v == 20])Output
['b', 'd']
Learn the concept
New to this topic? Read the lesson, then come back.