1s = {1: 1, 7: 2, 4: 2, 3: 1, 8: 1}
2k = dict(sorted(s.items(),key=lambda x:x[0],reverse = True))
3print(k)
1In [1]: import collections
2
3In [2]: d = {2:3, 1:89, 4:5, 3:0}
4
5In [3]: od = collections.OrderedDict(sorted(d.items()))
6
7In [4]: od
8Out[4]: OrderedDict([(1, 89), (2, 3), (3, 0), (4, 5)])
1def sort_dict(dictionary, rev = True):
2 l = list(dictionary.items())
3 l.sort(reverse = rev)
4 a = [item[1] for item in l]
5 z = ''
6 for x in a:
7 z = z + str(x)
8 return(z)