October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix 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 desk3 min

How to Convert a Dictionary to an Array in Python

Use list(data) for dictionary keys, list(data.values()) for values, or list(data.items()) for key/value tuples. For a NumPy ndarray, pass the chosen sequence to np.array().
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For most Python code, “convert a dictionary to an array” means make a list of its keys, values, or key/value pairs. Use list(data) for keys, list(data.values()) for values, and list(data.items()) for pairs. If you specifically need a NumPy array, pass the sequence you want to np.array().

Choose what the array should contain

Result Expression What it contains
List of keys list(data) or list(data.keys()) One dictionary key per element
List of values list(data.values()) One value per element, in the same order as its key
List of pairs list(data.items()) A (key, value) tuple for each entry
NumPy array of values np.array(list(data.values())) An ndarray built from the values sequence

For example:

data = {"name": "Ada", "age": 36}

keys = list(data)                 # ["name", "age"]
values = list(data.values())      # ["Ada", 36]
pairs = list(data.items())        # [("name", "Ada"), ("age", 36)]

Python documents list(d) as returning a dictionary’s keys. Choose values() or items() when the keys are not the data you need.

What order will the elements be in?

Dictionary iteration order is insertion order. Python guarantees this behavior from Python 3.7 onward; it does not mean the keys are automatically sorted. If you need sorted keys, request that explicitly, for example with sorted(data). See the Python dictionary documentation.

When a list is enough—and when a view is enough

The results of data.keys(), data.values(), and data.items() are dictionary views, not lists. A view can be iterated directly without making a separate list:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
for key, value in data.items():
    print(key, value)

Use list(...) when you need a materialized list—for example, to index the result or keep a separate snapshot of the current entries. Otherwise, iterating over the view avoids building that list.

When you specifically need a NumPy array

NumPy creates ndarrays from sequences such as lists and tuples. First choose which dictionary contents should become the sequence, then pass that sequence to np.array():

import numpy as np

scores = {"Ada": 98, "Lin": 91}
values = np.array(list(scores.values()))

This creates an array from the values. A sequence of numbers is a natural fit for numeric array operations. Dictionaries, however, can hold arbitrary objects, so mixed values or nested values with irregular shapes may not form the homogeneous, rectangular numeric array a task requires. Decide on the intended representation before converting. See NumPy’s array documentation.

For records or named fields

If the goal is tabular or record-shaped data rather than a simple sequence, a plain list of values may lose the association between field names and data. NumPy supports structured arrays with named fields, but its documentation notes that other projects may be better suited to tabular-data manipulation. See NumPy’s structured-array documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What about Python’s built-in typed array?

Python’s standard-library array module provides typed arrays, distinct from both a regular list and NumPy’s ndarray. Use it when its supported primitive types and typed-array behavior suit the program. For ordinary dictionary conversion, the list expressions above are usually the clearest; the module’s documentation also explains how to convert an array.array back to a list. See the Python array module documentation.

Common conversion mistakes

  • list(data) returns keys, not values. Use list(data.values()) to get values.
  • data.items() is a view, not a list. Wrap it in list() if you need a materialized list of tuples.
  • Dictionary order is insertion order, not sorted order. Sort explicitly when that is required.
  • A list, a NumPy ndarray, and an array.array are different types. Pick the one your next operation or API expects.
  • If keys must stay paired with their values, convert items() rather than extracting only one side.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.