Answers for "sort a dictionary ptyhon"

2

sort the dictionary in python

d = {2: 3, 1: 89, 4: 5, 3: 0}
od = sorted(d.items())
print(od)
Posted by: Guest on July-18-2020
0

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])
Posted by: Guest on May-18-2021

Python Answers by Framework

Browse Popular Code Answers by Language