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)
1d = {'one':1,'three':3,'five':5,'two':2,'four':4}
2
3# Sort
4a = sorted(d.items(), key=lambda x: x[1])
5
6# Reverse sort
7r = sorted(d.items(), key=lambda x: x[1], reverse=True)
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}
1#for dictionary d
2sorted(d.items(), key=lambda x: x[1]) #for inceasing order
3sorted(d.items(), key=lambda x: x[1], reverse=True) # for decreasing order
4#it will return list of key value pair tuples