Python Practice › Dictionary Programs › Program 67
Values for keys found in a list
Write a Python program to get the values of dictionary keys that are also in a list.
Input
["sqatools", "is", "best"], {"sqatools": 10}Output
[10]
Approach
- Loop over the list and look up keys that exist.
Solution
words = ["sqatools", "is", "best"]d = {"sqatools": 10}print([d[w] for w in words if w in d])Output
[10]
Learn the concept
New to this topic? Read the lesson, then come back.