#for dictionary dsorted(d.items(), key=lambda x: x[1])#for inceasing ordersorted(d.items(), key=lambda x: x[1], reverse=True)# for decreasing order#it will return list of key value pair tuples
In [1]:import collections
In [2]: d ={2:3,1:89,4:5,3:0}
In [3]: od = collections.OrderedDict(sorted(d.items()))
In [4]: od
Out[4]: OrderedDict([(1,89),(2,3),(3,0),(4,5)])
defsort_dict(dictionary, rev =True):
l =list(dictionary.items())
l.sort(reverse = rev)
a =[item[1]for item in l]
z =''for x in a:
z = z +str(x)return(z)