How to Convert a Dictionary to an Array in Python

Last month I was helping a small logistics company in Austin track quarterly bonuses for their 10-person warehouse team. Everything lived in a dictionary, employee names as keys, bonus amounts as values, because that’s the fastest way to store key-value pairs in Python. The problem showed up when their finance lead asked me to export that data into a CSV file and run some quick math with NumPy.

Dictionaries are great for lookups, but the moment you need to sort values, plug data into a chart, feed a machine learning model, or write rows to a spreadsheet, you need an array (usually a Python list or a NumPy array). I ran into this exact wall on that payroll project, and it made me realize how many beginners get stuck at this exact step.

By the end of this guide, you’ll know every practical way to convert a dictionary to an array in Python, when to use each one, and which approach actually fits your project.

Why You Need to Convert a Dictionary to an Array

A dictionary in Python stores data as key-value pairs, like {"John Smith": 500}. It’s unordered by design intent (even though modern Python preserves insertion order) and optimized for fast lookups by key. An array — whether that’s a plain Python list or a NumPy array, is optimized for sequential operations: sorting, slicing, math, and iteration by position.

Here’s the practical difference. If you ask “what’s John Smith’s bonus?” a dictionary answers instantly. If you ask “what’s the average bonus across the team?” you need every value lined up in a sequence you can run math on — that’s an array’s job. This is exactly why pandas DataFrames, NumPy, matplotlib, and most CSV writers expect list-like or array-like input, not dictionaries.

I’ll use one running example throughout this article: a bonus tracker for a 10-person warehouse team in Austin, Texas, stored as a Python dictionary.

bonus_data = {
"John Smith": 500,
"Emily Davis": 750,
"Michael Brown": 620,
"Sarah Wilson": 800,
"David Johnson": 450,
"Jessica Miller": 690,
"Daniel Garcia": 720,
"Ashley Martinez": 560,
"Christopher Lee": 810,
"Amanda Taylor": 640
}

This assumes Python 3.7+, since dictionary order preservation is guaranteed from that version onward. If you’re brand new to the language, it helps to first get comfortable with Python variables and how to initialize a dictionary in Python before jumping into conversions.

Method 1: Convert Dictionary Keys or Values to a List

The simplest and most common approach uses the built-in list() function combined with the dictionary’s .keys().values(), or .items() methods. This is the go-to method for 90% of real projects because it requires zero extra imports.

names_array = list(bonus_data.keys())
print(names_array)

Output:

['John Smith', 'Emily Davis', 'Michael Brown', 'Sarah Wilson', 'David Johnson', 'Jessica Miller', 'Daniel Garcia', 'Ashley Martinez', 'Christopher Lee', 'Amanda Taylor']

I executed the above example code and added the screenshot below.

Convert a Dictionary to an Array in Python

That single line pulls every key out of the dictionary and hands you back a clean list. To grab just the bonus amounts instead, swap .keys() for .values():

bonus_array = list(bonus_data.values())
print(bonus_array)

Output:

[500, 750, 620, 800, 450, 690, 720, 560, 810, 640]

This is the pattern I reach for whenever I just need one dimension of the data — either the names or the numbers, not both. If you want to know more about how .keys() behaves under the hood, check out how to get keys of a dictionary in Python.

Pro Tip: I’ve found that beginners often forget that .keys() and .values() return a special view object, not a list. If you try to index it directly like bonus_data.keys()[0], Python throws a TypeError. Always wrap it in list() first — it’s a one-second fix that saves you a confusing bug report later.

Method 2: Convert Dictionary Items to a List of Tuples

Sometimes you need both the key and value together, not separated into two arrays. That’s where .items() shines — it gives you a list of tuples, where each tuple pairs a name with its bonus.

items_array = list(bonus_data.items())
print(items_array)

Output:

[('John Smith', 500), ('Emily Davis', 750), ('Michael Brown', 620), ('Sarah Wilson', 800), ('David Johnson', 450), ('Jessica Miller', 690), ('Daniel Garcia', 720), ('Ashley Martinez', 560), ('Christopher Lee', 810), ('Amanda Taylor', 640)]

I executed the above example code and added the screenshot below.

How to Convert a Dictionary to an Python Array

I use this exact structure whenever I need to sort a dictionary by its values, since you can pass this list of tuples straight into sorted() with a key argument. For a deeper dive into that specific workflow, see sort a dictionary by value in Python and convert dictionary to list of tuples in Python.

This tuple-based array is also the exact input format that dict() expects if you ever need to rebuild a dictionary later, which makes it a safe intermediate format when you’re passing data between functions.

Method 3: Convert a Dictionary to a NumPy Array

If your end goal involves math — averages, standard deviation, or scaling values — a plain Python list isn’t ideal. That’s where NumPy, the standard numerical computing library, comes in. NumPy arrays support vectorized math, meaning you can run operations on the whole array at once instead of writing a loop.

First, install NumPy if you don’t already have it (pip install numpy), then convert your values directly:

import numpy as np

np_values = np.array(list(bonus_data.values()))
print(np_values)
print("Average bonus:", np_values.mean())
print("Total payout:", np_values.sum())

Output:

[500 750 620 800 450 690 720 560 810 640]
Average bonus: 654.0
Total payout: 6540

I executed the above example code and added the screenshot below.

Convert a Dictionary to an Python Array

Notice I still had to call list() first — NumPy’s array() function needs an iterable it can loop over, and a raw dict_values object works but converting explicitly avoids ambiguity. This is exactly the kind of quick math the Austin warehouse team needed for their quarterly report.

You can also build a 2D NumPy array that keeps names and bonuses paired together:

np_array = np.array(list(bonus_data.items()))
print(np_array)

Output:

[['John Smith' '500']
['Emily Davis' '750']
['Michael Brown' '620']
['Sarah Wilson' '800']
['David Johnson' '450']
['Jessica Miller' '690']
['Daniel Garcia' '720']
['Ashley Martinez' '560']
['Christopher Lee' '810']
['Amanda Taylor' '640']]

One thing to watch here: NumPy converts everything to a single data type, so your bonus numbers become strings ('500' instead of 500) because they’re mixed with text names in the same array. If you need numeric operations, keep names and values in separate arrays like in the first NumPy example. For more on this library, check out Python NumPy array and Python NumPy 2D array.

Method 4: Convert with a List Comprehension

A list comprehension is a compact way to build a list in a single line, and it gives you more control than the plain .keys() or .values() approach. This matters when you need to transform data during the conversion, not just extract it as-is.

Say the finance lead wanted every bonus formatted as a currency string instead of a raw number:

formatted_array = [f"${bonus:,.2f}" for bonus in bonus_data.values()]
print(formatted_array)

Output:

['$500.00', '$750.00', '$620.00', '$800.00', '$450.00', '$690.00', '$720.00', '$560.00', '$810.00', '$640.00']

Or you can build a 2D-style array where each row is a [name, bonus] pair, similar to what you’d want for a spreadsheet:

array_2d = [[name, bonus] for name, bonus in bonus_data.items()]
print(array_2d)

Output:

[['John Smith', 500], ['Emily Davis', 750], ['Michael Brown', 620], ['Sarah Wilson', 800], ['David Johnson', 450], ['Jessica Miller', 690], ['Daniel Garcia', 720], ['Ashley Martinez', 560], ['Christopher Lee', 810], ['Amanda Taylor', 640]]

That structure — a 2D array where each inner list is a row — is exactly what most CSV writers and spreadsheet libraries expect. If you’re new to comprehensions, it’s worth reading up on creating a 2D array in Python and initializing a 2D array in Python before combining them with dictionary logic.

Method 5: Convert a Dictionary to an Array Using pandas

When the end goal is reporting, exporting to Excel, or generating charts, converting straight to a pandas DataFrame first — then pulling out the array you need — is often cleaner than juggling raw lists.

import pandas as pd

df = pd.DataFrame(list(bonus_data.items()), columns=["Employee", "Bonus"])
print(df)

bonus_column_array = df["Bonus"].to_numpy()
print(bonus_column_array)

Output:

          Employee  Bonus
0 John Smith 500
1 Emily Davis 750
2 Michael Brown 620
3 Sarah Wilson 800
4 David Johnson 450
5 Jessica Miller 690
6 Daniel Garcia 720
7 Ashley Martinez 560
8 Christopher Lee 810
9 Amanda Taylor 640
[500 750 620 800 450 690 720 560 810 640]

This route is worth it when you need to sort, filter, or export the data afterward, since pandas gives you .to_csv().to_excel(), and .sort_values() for free. Read more on converting a Python dictionary to a pandas DataFrame and converting a pandas DataFrame to a NumPy array if this is the direction your project is heading.

Putting It Together: Exporting the Array to a CSV File

Once you’ve got your array, the natural next step in a real project is writing it to a file the finance team can open in Excel. Here’s the full flow, from dictionary to CSV, using the csv module that ships with Python:

import csv

with open("bonus_report.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Employee", "Bonus"])
for row in bonus_data.items():
writer.writerow(row)

This opens a file called bonus_report.csv in write mode, writes a header row, then loops through each key-value pair and writes it as a row. It’s a small script, but it’s the exact pattern I used for that Austin warehouse project — dictionary in, CSV out, no manual copy-pasting. For more on this pattern, see creating a CSV file in Python and writing an array to a file in Python.

Things to Keep in Mind

  • Watch for mixed data types in NumPy arrays. When you convert .items() directly into a NumPy array, every value gets cast to the same type (usually a string), which silently breaks numeric operations later.
  • Don’t assume dictionary order is guaranteed on old Python versions. Insertion order is only guaranteed from Python 3.7 onward — if your script needs to run on older environments, sort explicitly instead of relying on dictionary order.
  • Avoid hard-coded file paths when exporting. Use relative paths or the os.path module so your CSV export script works on any machine, not just yours.
  • Validate your dictionary values before converting. If a value is None or missing, your resulting array will carry that gap forward and break downstream math like .mean() or .sum().
  • Pick the right array type for the job. Use a plain list for simple iteration or CSV export, and a NumPy array only when you actually need vectorized math — importing NumPy for a 3-item list is overkill.
  • Keep large dictionaries out of memory-heavy loops. If you’re converting a dictionary with tens of thousands of entries, prefer list comprehensions or NumPy’s vectorized functions over manual for loops for better performance.

Frequently Asked Questions

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

Use the built-in list() function with .keys().values(), or .items() depending on what you need. For example, list(my_dict.values()) gives you an array of just the values, while list(my_dict.items()) gives you key-value pairs as tuples.

Can I convert a dictionary directly to a NumPy array?

Not directly — you first need to convert it to a list using .keys().values(), or .items(), then pass that list into np.array(). Converting .items() directly often results in a mixed-type array, so separate your keys and values first if you plan to do math.

What’s the difference between a Python list and a NumPy array?

A Python list can hold mixed data types and grows dynamically, but it’s slower for numeric operations. A NumPy array requires a single data type and is much faster for math because it uses vectorized, low-level operations instead of Python loops.

Why does my dictionary-to-array conversion lose the keys?

If you only convert .values(), you’re intentionally dropping the keys — that’s expected behavior. If you need both, convert .items() instead, which keeps keys and values paired together as tuples in the resulting array.

How do I sort a dictionary before converting it to an array?

Use the sorted() function on .items() with a key argument before converting, like sorted(my_dict.items(), key=lambda x: x[1]). This sorts by value while keeping the key-value pairs together, and the result is already a list you can use directly.

Is it faster to use a list comprehension or the built-in list() function?

For simple extraction without transformation, list(my_dict.values()) is faster since it avoids the overhead of an explicit loop. Use a list comprehension only when you need to transform each value during the conversion, like formatting numbers or filtering entries.

Converting a dictionary to an array in Python comes down to picking the right tool — list() for simple extraction, NumPy for math-heavy work, and pandas when reporting or exporting is the end goal. Start with the plain list() approach for most everyday scripts, and only reach for NumPy or pandas once your project actually needs their extra power. I hope you found this article helpful.

You May Also Like

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.