python sort list of dictionaries on key code example
Example 1: sort list of dictionaries by key python
newlist = sorted(list_to_be_sorted, key=lambda k: k['name'])
Example 2: how to sort a dictionary py
orders = {
'cappuccino': 54,
'latte': 56,
'espresso': 72,
'americano': 48,
'cortado': 41
}
sort_orders = sorted(orders.items(), key=lambda x: x[1], reverse=True)
for i in sort_orders:
print(i[0], i[1])