Values for keys found in a list

EasyDictionary Programs · 67 of 94

Write a Python program to get the values of dictionary keys that are also in a list.

Advertisement
Input
["sqatools", "is", "best"], {"sqatools": 10}
Output
[10]

Approach

  1. Loop over the list and look up keys that exist.

Solution

Python
words = ["sqatools", "is", "best"]d = {"sqatools": 10}print([d[w] for w in words if w in d])
Output
[10]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs