Find the keys of maximum values in a given dictionary.

In this python dictionary program, we will find the keys of maximum values in a given dictionary.

Steps to solve the program
  1. Take a dictionary as input.
  2. Sort the given dictionary in descending order by using sorted().
  3. In sorted use dictionary values as key to sort the dictionary using get().
  4. Print the keys of the first 2 maximum values in the dictionary using indexing.
				
					D1 =  {'a':18,'b':50,'c':36,'d':47,'e':60}
result = sorted(D1, key=D1.get, reverse=True)

print(result[:2])
				
			

Output :

				
					['e', 'b']
				
			

filter even numbers from a given dictionary value.

find the shortest list of values with the keys in a given dictionary.

Leave a Comment