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)
1A={1:2, -1:4, 4:-20}
2{k:A[k] for k in sorted(A)}
3
4output:
5{-1: 4, 1: 2, 4: -20}
1from operator import itemgetter
2new_dict = sorted(data.items(), key=itemgetter(1))
1orders = {
2 'cappuccino': 54,
3 'latte': 56,
4 'espresso': 72,
5 'americano': 48,
6 'cortado': 41
7}
8
9sort_orders = sorted(orders.items(), key=lambda x: x[1], reverse=True)
10
11for i in sort_orders:
12 print(i[0], i[1])