While working on a data project for a U.S.-based retail analytics company, I needed to convert a Python dictionary into an array for some quick numerical analysis using NumPy.
At first, it seemed simple; after all, a dictionary and an array both store data. But when I dug deeper, I realized that depending on what exactly I wanted (keys, values, or both), there were several efficient ways to handle this conversion.
In this tutorial, I’ll walk you through different methods to convert a Python dictionary to an array, step by step. I’ll also explain when to use each method and why.
What Is a Python Dictionary?
A Python dictionary is a collection of key-value pairs. It’s one of the most powerful and flexible data structures in Python, allowing you to map unique keys to specific values.
Here’s a quick example of a Python dictionary:
employee_data = {
"John": 85000,
"Emma": 92000,
"Liam": 78000,
"Olivia": 97000
}In this dictionary, each employee’s name is a key, and their salary is the value. Now, let’s see how we can convert this dictionary into various types of arrays.
Method 1 – Convert Python Dictionary to an Array of Tuples Using items()
The simplest way to convert a Python dictionary to an array is by using the built-in items() method. This method returns a view object containing the dictionary’s key-value pairs as tuples.
Here’s how I do it in my projects:
employee_data = {
"John": 85000,
"Emma": 92000,
"Liam": 78000,
"Olivia": 97000
}
# Convert to array of tuples
employee_array = list(employee_data.items())
print(employee_array)Output:
[('John', 85000), ('Emma', 92000), ('Liam', 78000), ('Olivia', 97000)]You can refer to the screenshot below to see the output.

This method is quick and easy when you want both keys and values together. Each element in the resulting array is a tuple, which preserves the relationship between the key and its corresponding value.
Method 2 – Convert Python Dictionary Keys to an Array
Sometimes, you may only need the keys from a dictionary, for example, when you’re building a dropdown list of employee names in a web app.
Here’s how to extract just the keys as an array:
employee_data = {
"John": 85000,
"Emma": 92000,
"Liam": 78000,
"Olivia": 97000
}
# Convert keys to array
keys_array = list(employee_data.keys())
print(keys_array)Output:
['John', 'Emma', 'Liam', 'Olivia']You can refer to the screenshot below to see the output.

This approach is perfect when you only need to work with identifiers, such as usernames, product IDs, or state codes.
Method 3 – Convert Python Dictionary Values to an Array
If your focus is on the values (like salaries, prices, or scores), you can easily extract them using the values() method.
Here’s how:
employee_data = {
"John": 85000,
"Emma": 92000,
"Liam": 78000,
"Olivia": 97000
}
# Convert values to array
values_array = list(employee_data.values())
print(values_array)Output:
[85000, 92000, 78000, 97000]You can refer to the screenshot below to see the output.

This method is especially useful when performing numerical operations such as calculating averages or plotting data.
Method 4 – Convert Python Dictionary to NumPy Array
If you’re working with data analysis or machine learning, you’ll often need to convert your dictionary into a NumPy array for faster computation.
NumPy provides the array() function, which can convert lists or tuples into an array format that supports mathematical operations.
Here’s how to do it:
import numpy as np
employee_data = {
"John": 85000,
"Emma": 92000,
"Liam": 78000,
"Olivia": 97000
}
# Convert dictionary items to NumPy array
numpy_array = np.array(list(employee_data.items()))
print(numpy_array)Output:
[['John' '85000']
['Emma' '92000']
['Liam' '78000']
['Olivia' '97000']]You can refer to the screenshot below to see the output.

This method is ideal when you’re preparing data for numerical analysis or exporting it to a machine learning model.
You can also extract only the values as a NumPy array for calculations:
salary_array = np.array(list(employee_data.values()))
print(salary_array)Output:
[85000 92000 78000 97000]Now you can easily compute statistics like mean or standard deviation using NumPy functions.
Method 5 – Convert Python Dictionary to Array Using List Comprehension
List comprehension is one of my favorite Python features. It’s concise, readable, and powerful.
You can use it to convert a dictionary into an array in various ways. For example, let’s create an array of formatted strings from our dictionary:
# Python dictionary
employee_data = {
"John": 85000,
"Emma": 92000,
"Liam": 78000,
"Olivia": 97000
}
# Convert to array using list comprehension
formatted_array = [f"{key}: ${value}" for key, value in employee_data.items()]
print(formatted_array)Output:
['John: $85000', 'Emma: $92000', 'Liam: $78000', 'Olivia: $97000']This approach gives you full control over how you want to structure your array elements. It’s perfect when you need to prepare data for display, reporting, or exporting to a CSV file.
Method 6 – Convert Python Dictionary to Array Using zip()
The zip() function is another elegant way to convert a dictionary into an array of keys and values.
Here’s how I use it in real-world Python projects:
# Python dictionary
employee_data = {
"John": 85000,
"Emma": 92000,
"Liam": 78000,
"Olivia": 97000
}
# Convert dictionary to array using zip()
keys = list(employee_data.keys())
values = list(employee_data.values())
zipped_array = list(zip(keys, values))
print(zipped_array)Output:
[('John', 85000), ('Emma', 92000), ('Liam', 78000), ('Olivia', 97000)]This method is similar to items(), but it gives you more flexibility; for instance, you can modify the keys or values before zipping them together.
Method 7 – Convert Nested Python Dictionary to Array
Sometimes, you’ll encounter dictionaries within dictionaries (nested dictionaries). Let’s see how to flatten and convert them into an array.
# Nested dictionary
employee_data = {
"Department A": {"John": 85000, "Emma": 92000},
"Department B": {"Liam": 78000, "Olivia": 97000}
}
# Convert nested dictionary to array
nested_array = [(dept, emp, sal) for dept, data in employee_data.items() for emp, sal in data.items()]
print(nested_array)Output:
[('Department A', 'John', 85000),
('Department A', 'Emma', 92000),
('Department B', 'Liam', 78000),
('Department B', 'Olivia', 97000)]This approach is extremely useful when you’re working with hierarchical data, such as department-wise employee salaries or state-wise sales figures in a U.S. dataset.
Bonus Tip – Convert Python Dictionary to Array and Save as CSV
After converting your dictionary to an array, you might want to save it for later use. Here’s how to export the array to a CSV file using Python’s built-in csv module:
import csv
# Dictionary
employee_data = {
"John": 85000,
"Emma": 92000,
"Liam": 78000,
"Olivia": 97000
}
# Convert dictionary to array
employee_array = list(employee_data.items())
# Save to CSV
with open("employee_salaries.csv", "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Employee", "Salary"])
writer.writerows(employee_array)
print("Data saved successfully to employee_salaries.csv")This simple snippet helps you store your converted array for reports, dashboards, or data exchange.
Converting a Python dictionary to an array is a common and practical task, especially when dealing with data analysis, visualization, or machine learning workflows.
Whether you use items(), keys(), values(), numpy.array(), or even list comprehension, the right method depends on your specific use case.
Personally, I prefer NumPy arrays when working with numerical data and list comprehension when I need flexibility in formatting.
You may also like to read:
- Remove Item from Set in Python
- Check if a Python Set is Empty
- Add Item to Set in Python
- Create an Empty Set in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.