-Here we try to sort the dictionary data according to the keys length.
Example-
dictionary is {'first':1,'four':4,'six':6}
then after sort dictionary become {'six':6,'four':4,'first':1}
program-
#import the OrderedDict from collections module
from collections import OrderedDict
#given unsorted dictionary
d={'first':1,'four':4,'six':6}
print("Dictionary is:",d)
#sort according to keys length of dictionary
x=OrderedDict(sorted(d.items(), key=lambda t: len(t[0])))
print("After sort by key length, dictionary is")
print(x)
Dictionary is: {'first': 1, 'four': 4, 'six': 6}
After sort by value, dictionary is
OrderedDict([('six', 6), ('four', 4), ('first', 1)])