Sort a list of values in a dictionary.

In this python dictionary program, we will sort a list of values in a dictionary.

Steps to solve the program
  1. Take a dictionary as input.
  2. Use for loop to iterate over a list of values of the given dictionary using values().
  3. During iteration sort the list of values using sort().
  4. Print the output.
				
					dict1 = {'a1':[1,5,3],'a2':[10,6,20]}

for val in dict1.values():
    val.sort()
    
print(dict1)
				
			

Output :

				
					{'a1': [1, 3, 5], 'a2': [6, 10, 20]}
				
			

convert a list into a nested dictionary of keys

get a product with the highest price from a dictionary.

Leave a Comment