In this python dictionary program, we will sort a list of values in a dictionary.
Steps to solve the program
- Take a dictionary as input.
- Use for loop to iterate over a list of values of the given dictionary using values().
- During iteration sort the list of values using sort().
- 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]}