Manuel Aráoz Manuel Aráoz - 15 days ago 4
Python Question

Tuple list from dict in Python

How can I obtain a list of key-value tuples from a dict in Python?

Answer

For Python 2.x only (thanks Alex):

yourdict = {}
# ...
items = yourdict.items()

See http://docs.python.org/library/stdtypes.html#dict.items for details.

For Python 3.x only (taken from Alex's answer):

yourdict = {}
# ...
items = list(yourdict.items())