Find all keys in the provided dictionary that have the given value.

In this python dictionary program, we will find all keys in the provided dictionary that have the given value.

Steps to solve the program
  1. Take a dictionary as input and create an empty list.
  2. Use for loop to iterate over keys and values of the dictionary.
  3. If a value is equal to 0 then add its key to the list using append().
  4. 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']
				
			

convert a list of dictionaries into a list of values corresponding to the specified key.

convert given a dictionary to a list of tuples.

Leave a Comment