Skip to content

Latest commit

 

History

History
17 lines (14 loc) · 647 Bytes

convert-dictionary-keys-values-list.md

File metadata and controls

17 lines (14 loc) · 647 Bytes

Convert dictionary values or keys to list

In Python 3, the dict.keys() or dict.values() method returns a dictionary view object, which acts as a set. Iterating over the dictionary directly also yields keys, so turning a dictionary into a list results in a list of all the keys or values.

orders = {
	'cappuccino': 54,
	'latte': 56,
	'espresso': 72,
	'americano': 48,
	'cortado': 41
}

keys = list(orders.keys())
values = list(orders.values())

Source