Shortest list of values with the keys in a dictionary.

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

Steps to solve the program
  1. Take a dictionary in the given format as input and create an empty list.
  2. Use for loop to iterate over keys and values of the input dictionary.
  3. If the length of the value list is 1, then add the key for the value list to the empty list.
  4. Print the output.
				
					D1 = {'a':[10,12],'b':[10],'c':[10,20,30,40],'d':[20]}
keys = []

for k,v in D1.items():
    if len(v) == 1:
        keys.append(k)
        
print(keys)
				
			

Output :

				
					['b', 'd']
				
			

find the keys of maximum values in a given dictionary.

count the frequency in a given dictionary.

Leave a Comment