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)
1>>> d = {"aa": 3, "bb": 4, "cc": 2, "dd": 1}
2>>> for k in sorted(d, key=d.get, reverse=True):
3... k, d[k]
4...
5('bb', 4)
6('aa', 3)
7('cc', 2)
8('dd', 1)
1x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
2{k: v for k, v in sorted(x.items(), key=lambda item: item[1])}
3{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}
1from collections import OrderedDict
2dd = OrderedDict(sorted(d.items(), key=lambda x: x[1]))
3print(dd)