October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Convert a Dictionary to a List in Python

Use list(d) for keys, list(d.values()) for values, and list(d.items()) for key-value tuples. Python dictionaries preserve insertion order from Python 3.7 onward.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the list contents you need: list(d) makes a list of keys, list(d.values()) makes a list of values, and list(d.items()) makes a list of (key, value) tuples.

Choose what the list should contain

For a dictionary such as d = {"a": 1, "b": 2}, use the form that matches the result you want:

Output Python Result
Keys list(d) ['a', 'b']
Values list(d.values()) [1, 2]
Key-value pairs list(d.items()) [('a', 1), ('b', 2)]

Keys: list(d)

Iterating over a dictionary yields its keys, so list(d) is the concise way to create a list of them. list(d.keys()) produces the same result, but is usually unnecessary. Python’s data-structures tutorial documents both the key behavior and the sorted-key alternative.

Values: list(d.values())

The values() method provides a view of the dictionary’s values; passing it to list() materializes those values as a list. Values remain in the order associated with their keys.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pairs: list(d.items())

The items() method provides a view of the key-value pairs. Converting it to a list gives one two-element tuple per dictionary entry, which is useful when later code needs both the key and its value.

Understand the order of the result

For Python 3.7 and later, dictionaries preserve insertion order as a language guarantee. These conversions therefore follow the dictionary’s current order. In CPython 3.6, insertion order was preserved as an implementation detail, not guaranteed by the language. The built-in types reference documents the version distinction.

Changing the value of an existing key does not move it. If a key is deleted and then inserted again, it appears at the end of the order. This behavior is specified in Python’s data model reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Sort keys when order should be alphabetical

Use sorted(d) to get a list of keys in sorted order rather than insertion order. Sorting requires the keys to be comparable with one another; for example, a mix of incomparable types can cause sorting to fail. Python’s tutorial section on data structures notes that not all values can be compared or sorted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

sorted(d) sorts the keys, not the values or pairs. If you need a different output shape, first decide which elements belong in the list; sorting is a separate choice from converting.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.