In this python dictionary program, we will find all keys in the provided dictionary that have the given value.
Steps to solve the program
- Take a dictionary as input and create an empty list.
- Use for loop to iterate over keys and values of the dictionary.
- If a value is equal to 0 then add its key to the list using append().
- Print the output.
D1 = {'a':19,'b':20,'c':21,'d':20}
l = []
for k,v in D1.items():
if v == 20:
l.append(k)
print(l)
Output :
['b', 'd']