How to Convert a Dictionary to a List in Python

To convert a dictionary to a list in Python, call list() on the part you want: list(d) gives the keys, list(d.values()) the values, and list(d.items()) a list of (key, value) tuples. All three keep the dictionary’s insertion order:

list(prices.values())   # [14.99, 9.5, 4.25]
list(prices.items())    # [('Coffee beans', 14.99), ...]

A small store price list runs through every example; I ran them on Python 3.12.5, where dicts always keep insertion order.

You’ll see keys, values and items as lists, the ‘dict_values’ subscript error, filtering and sorting while converting, flattening a dict of lists, and turning nested dicts into rows.

Convert a dictionary to a list of keys, values or items

Pick the view you need and wrap it in list(). For pairs that must be lists rather than tuples, say for JSON, use a comprehension:

prices = {"Coffee beans": 14.99, "Mug": 9.50, "Filters": 4.25}

print(list(prices))            # keys
print(list(prices.values()))   # values
print(list(prices.items()))    # (key, value) tuples
print([[k, v] for k, v in prices.items()])   # pairs as lists, e.g. for JSON

Output:

['Coffee beans', 'Mug', 'Filters']
[14.99, 9.5, 4.25]
[('Coffee beans', 14.99), ('Mug', 9.5), ('Filters', 4.25)]
[['Coffee beans', 14.99], ['Mug', 9.5], ['Filters', 4.25]]
Command Prompt output of Python converting a price dictionary to lists of keys, values, key-value tuples and key-value lists
The same dictionary becomes a list of item names, a list of prices, a list of tuples and a list of two-item lists.

list(d) and list(d.keys()) are the same. For more on the values case, see converting dictionary values to a list.

Why do I get ‘dict_values’ object is not subscriptable?

d.values() returns a view, not a list, so you can’t index it. Convert it first, or use next(iter(...)) for just the first value:

prices = {"Coffee beans": 14.99, "Mug": 9.50, "Filters": 4.25}
values = prices.values()

try:
    print(values[0])
except TypeError as err:
    print("TypeError:", err)

print(list(values)[0])
print(next(iter(values)))      # first value without building a list

prices["Kettle"] = 39.00
print(values)                  # a view: it sees the new item

Output:

TypeError: 'dict_values' object is not subscriptable
14.99
14.99
dict_values([14.99, 9.5, 4.25, 39.0])
Command Prompt output of Python TypeError dict_values object is not subscriptable, then list() and next(iter()) working
Indexing the values view raises TypeError; list(values)[0] and next(iter(values)) both return 14.99, and the view later shows the added Kettle.

Views stay live: add a key and the view shows it. Keys work the same way, as in getting the keys of a dictionary.

Filter and sort while converting a dictionary to a list

A comprehension can pick and reshape items in the same step. sorted() on items() sorts by key, or by value with a key function:

prices = {"Coffee beans": 14.99, "Mug": 9.50, "Filters": 4.25, "Kettle": 39.00, "Grinder": 89.99}

over_10 = [item for item, price in prices.items() if price > 10]
print("over $10:", over_10)

by_price = sorted(prices.items(), key=lambda kv: kv[1], reverse=True)
print("most expensive first:", by_price[:3])

labels = [f"{item}: ${price:.2f}" for item, price in prices.items()]
print(labels)

Output:

over $10: ['Coffee beans', 'Kettle', 'Grinder']
most expensive first: [('Grinder', 89.99), ('Kettle', 39.0), ('Coffee beans', 14.99)]
['Coffee beans: $14.99', 'Mug: $9.50', 'Filters: $4.25', 'Kettle: $39.00', 'Grinder: $89.99']
Command Prompt output of Python building filtered and sorted lists from a price dictionary and formatting labels in dollars
Items over $10 are listed, the three most expensive come first with their prices, and every item becomes a dollar label.

For the pairs as tuples in more depth, see converting a dictionary to a list of tuples.

Flatten a dictionary of lists into one list

When each value is itself a list, a nested comprehension or itertools.chain joins them into one list:

from itertools import chain

stock = {"Austin": ["Mug", "Kettle"], "Denver": ["Beans"], "Tampa": ["Mug", "Filters"]}

flat = [item for items in stock.values() for item in items]
print(flat)
print(list(chain.from_iterable(stock.values())))
print(sorted(set(flat)))

pairs = [x for kv in {"TX": 3, "CO": 1}.items() for x in kv]     # keys and values interleaved
print(pairs)

Output:

['Mug', 'Kettle', 'Beans', 'Mug', 'Filters']
['Mug', 'Kettle', 'Beans', 'Mug', 'Filters']
['Beans', 'Filters', 'Kettle', 'Mug']
['TX', 3, 'CO', 1]
Command Prompt output of Python flattening a dictionary of store inventories into one list with a comprehension and itertools.chain
Both methods give one list of five items, the set removes the repeated Mug, and the last line interleaves keys and values.

Wrap the result in set() when repeats don’t matter. Building this kind of dict in the first place is covered in a Python dictionary of lists.

Convert a dictionary of dictionaries to a list of records

APIs often return records keyed by ID. Merge the key into each record to get a list you can sort, filter or write to CSV:

orders = {
    1001: {"customer": "Emily Carter", "state": "TX", "total": 129.99},
    1002: {"customer": "James Wilson", "state": "CO", "total": 54.50},
}

rows = [{"id": oid, **data} for oid, data in orders.items()]
print(rows)

totals = [o["total"] for o in orders.values()]
print(totals, f"sum ${sum(totals):.2f}")

Output:

[{'id': 1001, 'customer': 'Emily Carter', 'state': 'TX', 'total': 129.99}, {'id': 1002, 'customer': 'James Wilson', 'state': 'CO', 'total': 54.5}]
[129.99, 54.5] sum $184.49

{"id": oid, **data} builds a new dict without changing the original. The reverse direction is covered in creating a dictionary from two lists.

Dictionary to list methods compared

You wantCode
Keyslist(d)
Valueslist(d.values())
(key, value) tupleslist(d.items())
[key, value] lists[[k, v] for k, v in d.items()]
Sorted by valuesorted(d.items(), key=lambda kv: kv[1])
Flattened values[x for v in d.values() for x in v]

More conversions between Python’s built-in types:

Frequently asked questions

How do I convert a dictionary to a list in Python?

Use list(d) for keys, list(d.values()) for values or list(d.items()) for key-value pairs.

Does converting a dict to a list keep the order?

Yes. Since Python 3.7, dictionaries keep insertion order, and list() follows it.

Why can’t I index d.values()?

It’s a view object, not a list. Use list(d.values())[0] or next(iter(d.values())).

How do I get a list of key-value lists instead of tuples?

Use [[k, v] for k, v in d.items()].

How do I convert a dict to a list sorted by value?

Use sorted(d.items(), key=lambda kv: kv[1]); add reverse=True for largest first.

Where are dictionary views documented?

See dictionary view objects in the Python docs.