-Here we try to sort the dictionary data according to the values.
Example-
dictionary is {'c':1,'a':4,'z':2}
then after sort dictionary become {'c':1,'z':2,'a':4}
program-
#import the OrderedDict from collections module
from collections import OrderedDict
#given unsorted dictionary
d={'b':3,'a':2,'c':4,'d':1}
print("Dictionary is:",d)
#sort according to values of dictionary
x=OrderedDict(sorted(d.items(), key=lambda t: t[1]))
print("After sort by values, dictionary is")
print(x)
Dictionary is: {'b': 3, 'a': 2, 'c': 4, 'd': 1}
After sort by values, dictionary is
OrderedDict([('d', 1), ('a', 2), ('b', 3), ('c', 4)])