HOWTO · Python
How to Convert a Dictionary to a List in Python
This article introduces how to convert a dictionary into a list in Python.
On this page
A Python dictionary stores key-value pairs. “Convert a dictionary to a list” can mean three different results: a list of keys, a list of values, or a list of (key, value) tuples. Choose the form your next operation needs; wrap the corresponding dictionary view in list() to materialize it.
Choose which part of a dictionary to convert
Use keys() when the list should contain dictionary keys, values() for the values, and items() for paired keys and values. The examples below use one dictionary throughout. Run each Python example to inspect its result in your environment.
Convert dictionary keys and values to lists
keys() and values() are dictionary methods. In Python 3 they provide views, which list() turns into lists. The key and value lists follow the dictionary’s iteration order and correspond position by position.
dictionary = {"a": "Apple", "b": "Banana", "c": "Cherries", "d": "Dragon Fruit"}
keys = list(dictionary.keys())
values = list(dictionary.values())
print(type(dictionary.keys()))
print(keys)
print(values)
Use list(dictionary) as a shorter way to create a list of keys. Choose list(dictionary.keys()) when naming the method makes the intent clearer. If you only need to loop over keys or values, you can iterate over the view directly instead of allocating a list.
Convert dictionary items to a list of tuples
For key-value pairs, call items() and pass its view to list(). Each element in the resulting list is a two-item tuple: the key followed by its value.
dictionary = {"a": "Apple", "b": "Banana", "c": "Cherries", "d": "Dragon Fruit"}
pairs = list(dictionary.items())
print(type(dictionary.items()))
print(pairs)
This is the direct approach when you need pairs. zip(dictionary.keys(), dictionary.values()) is another way to pair the two sequences from the same dictionary, but it adds no benefit for this task and is easier to misuse if the inputs come from different sources. Prefer items() for ordinary dictionary pairs.
Understand Python 3 dictionary views and ordering
In Python 3, keys(), values(), and items() return view objects rather than lists. A view is useful for iteration; list() makes a separate list when a list is required. The type inspection in the examples distinguishes a view from the materialized list.
The examples show the entries in the dictionary’s iteration order, with keys and values aligned. If you need a particular order independent of how the dictionary was built, sort explicitly—for example, sort the keys before using them. Do not rely on a displayed order from another dictionary as a substitute for defining the order your task requires.
Handle Python 2 compatibility
iteritems() is a legacy Python 2 dictionary method. It is not the Python 3 items() example shown above, and the legacy syntax below is illustrative only; do not run it as Python 3 code:
pairs = list(dictionary.iteritems()) (Python 2 only; illustrative syntax, not a Python 3 example.)
For Python 3, use list(dictionary.items()). The article’s supplied legacy example does not provide a reliable reason to state a particular Python 2 ordering or type display, so those details are omitted. If maintaining old Python 2 code, verify behavior in the exact interpreter and codebase you support rather than assuming the Python 3 example transfers unchanged.