How to convert a dictionary to a list in Python

Learn to convert a Python dictionary to a list. Explore various methods, see real-world applications, and get tips for debugging errors.

How to convert a dictionary to a list in Python
Published on: 
Tue
Mar 3, 2026
Updated on: 
Fri
Mar 6, 2026
The Replit Team Logo Image
The Replit Team

You often need to convert a Python dictionary to a list for data manipulation. This task lets you extract keys, values, or both into an ordered sequence for further processing.

In this guide, you'll explore several techniques for this conversion. You'll learn about methods like .keys() and .values(), and find practical tips, real-world applications, and debugging advice.

Converting a dictionary to a list with list()

my_dict = {'a': 1, 'b': 2, 'c': 3}
keys_list = list(my_dict)
print(keys_list)--OUTPUT--['a', 'b', 'c']

Wrapping a dictionary with the list() constructor is a direct way to get a list of its keys. This works because when you iterate over a dictionary in Python, it yields its keys by default. The list() function simply collects these keys into a new list for you.

This approach is both concise and efficient. Since Python 3.7, you can also count on the list preserving the original insertion order of the keys, making it a predictable operation.

Basic dictionary to list conversions

For more granular control than the list() constructor offers, you can use dedicated dictionary methods to pull out just the keys, values, or both.

Getting a list of keys with dict.keys()

my_dict = {'a': 1, 'b': 2, 'c': 3}
keys_list = list(my_dict.keys())
print(keys_list)--OUTPUT--['a', 'b', 'c']

Using the .keys() method is a more explicit way to grab a dictionary's keys. It returns a special view object that contains the keys, not a list itself.

  • To get an actual list, you must convert this view object using the list() constructor.
  • This approach improves code readability by clearly signaling your intent to work specifically with the dictionary's keys.

Getting a list of values with dict.values()

my_dict = {'a': 1, 'b': 2, 'c': 3}
values_list = list(my_dict.values())
print(values_list)--OUTPUT--[1, 2, 3]

Similar to .keys(), the .values() method is the explicit way to isolate a dictionary's values. It provides a clear and readable approach when you don't need the keys.

  • This method returns a dynamic view object, not a list directly.
  • To get a standard list, you must convert this view by wrapping it with the list() constructor.
  • The resulting list preserves the original insertion order of the values.

Getting a list of key-value tuples with dict.items()

my_dict = {'a': 1, 'b': 2, 'c': 3}
items_list = list(my_dict.items())
print(items_list)--OUTPUT--[('a', 1), ('b', 2), ('c', 3)]

When you need to keep keys and values paired together, the .items() method is the perfect tool. It returns a view object where each item is a tuple containing a key and its corresponding value. To get a list of these tuples, you just wrap the result with the list() constructor.

  • This approach is ideal when you need to iterate over both keys and values at the same time.
  • The resulting list of tuples maintains the original insertion order from your dictionary.

Advanced dictionary to list techniques

Beyond simple extraction, you can also apply custom logic during the conversion process to transform your dictionary data into more tailored list structures.

Using list comprehensions for custom transformations

my_dict = {'a': 1, 'b': 2, 'c': 3}
formatted_list = [f"{key}:{value}" for key, value in my_dict.items()]
print(formatted_list)--OUTPUT--['a:1', 'b:2', 'c:3']

List comprehensions give you a concise way to build a new list by processing items from another sequence. Here, the comprehension loops through each key-value pair provided by my_dict.items(). It then uses an f-string, f"{key}:{value}", to format each pair into a single string.

  • This approach lets you define both the loop and the transformation in one readable line.
  • It’s a flexible method for creating lists with custom structures, going beyond simple key or value extraction.

This is often considered more "Pythonic" than a standard for loop.

Applying map() with lambda functions

my_dict = {'a': 1, 'b': 2, 'c': 3}
doubled_values = list(map(lambda item: (item[0], item[1]*2), my_dict.items()))
print(doubled_values)--OUTPUT--[('a', 2), ('b', 4), ('c', 6)]

The map() function offers another way to transform dictionary items. It works by applying a function to every item in a sequence. Here, a lambda function defines a quick, one-time operation without the need to formally declare a separate function.

  • The lambda function, lambda item: (item[0], item[1]*2), processes each key-value tuple from my_dict.items().
  • It creates a new tuple, keeping the original key (item[0]) while doubling the value (item[1]).
  • Since map() returns a special map object, you wrap it with list() to get the final list.

Creating nested lists from dictionary entries

my_dict = {'a': 1, 'b': 2, 'c': 3}
nested_list = [[key, value] for key, value in my_dict.items()]
print(nested_list)--OUTPUT--[['a', 1], ['b', 2], ['c', 3]]

This list comprehension turns your dictionary into a nested list. It loops over the key-value pairs from my_dict.items(), but instead of creating a string, it builds a new list, [key, value], for each pair.

  • The final output is a list that contains these smaller lists.
  • This structure is great when you need mutable pairs, since lists can be changed, unlike the immutable tuples you get from just converting .items().

Move faster with Replit

Replit is an AI-powered development platform that transforms natural language into working applications. Describe what you want to build, and Replit Agent creates it—complete with databases, APIs, and deployment.

For the dictionary conversion techniques we've explored, Replit Agent can turn them into production-ready tools:

  • Build a simple inventory tracker that converts product data into a list of [item, quantity] pairs for easy display and management.
  • Create a configuration file exporter that transforms settings from a dictionary into a formatted list of key:value strings.
  • Deploy a data analysis utility that extracts numerical values from a dictionary to calculate statistics like averages or totals.

Try it yourself. Describe an application to Replit Agent, and it will write the code, handle testing, and fix issues automatically, all within your browser.

Common errors and challenges

While converting dictionaries to lists is straightforward, a few common slip-ups can lead to bugs or confusing results.

Misunderstanding what list(dictionary) returns

A frequent mistake is assuming that list(dictionary) will return values or key-value pairs. It only returns the keys. This happens because iterating over a dictionary defaults to its keys, and the list() constructor just collects what it's given. If you need values or the pairs, you'll have to explicitly ask for them with .values() or .items().

Trying to calculate with keys instead of values

Another common issue is trying to perform calculations on a list of keys instead of values. For example, you might convert a dictionary to a list and then try to find the sum, expecting to add up numerical values. If you haven't explicitly extracted the values using .values(), you'll end up with a list of keys, which will likely cause a TypeError if you try to perform math on them.

Losing key-value relationships when creating separate lists

It can be tempting to create two separate lists, one for keys and one for values. While this works, you lose the inherent link between each key and its value. If you sort or modify one list without applying the same change to the other, your data will become mismatched. For tasks where the key-value pairing is important, it's much safer to use .items() to create a list of tuples, keeping each pair intact.

Misunderstanding what list(dictionary) returns

It's easy to assume that wrapping a dictionary in list() will capture everything inside. However, this conversion only grabs the keys, which can lead to unexpected behavior when you try to access the values you thought were there. The following code demonstrates this common pitfall.

user_data = {'name': 'John', 'age': 30, 'city': 'New York'}
# Expecting to get both keys and values
data_list = list(user_data)
print(f"Name: {data_list[0]}, Age: {data_list[1]}")  # Will print keys, not values

The code incorrectly assumes data_list contains values. Instead, it holds keys like 'name' and 'age', causing the print statement to display the wrong information. The corrected version below shows the right approach.

user_data = {'name': 'John', 'age': 30, 'city': 'New York'}
# Convert to list of tuples for both keys and values
data_list = list(user_data.items())
print(f"Name: {data_list[0][1]}, Age: {data_list[1][1]}")  # Access values correctly

The solution is to use the .items() method, which creates a list of (key, value) tuples. This keeps each key correctly paired with its value. You can then access a specific value by indexing the tuple and then the element within it, like data_list[0][1]. It's crucial to use this approach whenever you need to work with both keys and values together, ensuring your data pairs don't get mixed up during processing.

Trying to calculate with keys instead of values

It's a classic mix-up: you convert a dictionary to a list, then try to run a calculation like sum(). But if you haven't explicitly extracted the numerical values with .values(), you'll be trying to add up the keys, leading to an error.

The following code snippet shows what happens when you accidentally try to sum a list of string keys instead of their corresponding float values.

product_prices = {'apple': 1.20, 'banana': 0.50, 'orange': 0.75}
product_list = list(product_prices)
# Attempting to calculate with keys instead of values
total = sum(product_list)  # TypeError: unsupported operand type(s) for +
print(f"Total price: ${total:.2f}")

The code triggers a TypeError because the sum() function receives a list of strings. Python can't perform mathematical addition on text like 'apple' and 'banana'. The following snippet shows the correct way to handle this.

product_prices = {'apple': 1.20, 'banana': 0.50, 'orange': 0.75}
# Correctly sum the values
total = sum(product_prices.values())
print(f"Total price: ${total:.2f}")

The fix is to explicitly target the dictionary's values using the .values() method. This provides the sum() function with the numbers it needs, allowing the calculation to succeed. This kind of error often appears when you're aggregating data—for example, calculating total sales from a product dictionary or averaging scores from a student record. Always make sure you're feeding numerical functions the values, not the keys.

Losing key-value relationships when creating separate lists

It's risky to split a dictionary into separate key and value lists because you lose their inherent connection. If one list is sorted or modified without the other, the data becomes mismatched, leading to subtle bugs that are hard to trace.

The following code demonstrates this fragility by trying to match a student's name to their score using separate lists.

scores = {'Alice': 95, 'Bob': 87, 'Charlie': 92}
names = list(scores.keys())
points = list(scores.values())
# Trying to match top score with student name
max_score = max(points)
top_student_index = points.index(max_score)
print(f"Top student: {names[top_student_index]}")  # Breaks if order changes

This code finds the top score's index in the points list and uses it to retrieve the name from the names list. This method is fragile because it depends on the lists staying perfectly aligned. The following example shows a more robust approach.

scores = {'Alice': 95, 'Bob': 87, 'Charlie': 92}
# Keep key-value relationship intact
items_list = list(scores.items())
top_scorer = max(items_list, key=lambda x: x[1])
print(f"Top student: {top_scorer[0]} with {top_scorer[1]} points")

The robust solution is to convert the dictionary into a list of tuples using .items(), which keeps each name and score pair together. This approach is essential for tasks like ranking or finding extremes without breaking data integrity.

  • The max() function then uses a key argument, lambda x: x[1], to find the highest value by looking only at the second item in each tuple—the score.

Real-world applications

With the common pitfalls in mind, you can confidently use methods like values() and items() for practical tasks like sorting data and analyzing text.

Sorting dictionary data by values()

You can rank dictionary entries by value, like creating a student leaderboard, by using the sorted() function on the key-value pairs from the .items() method.

student_scores = {'Alice': 92, 'Bob': 85, 'Charlie': 97, 'Diana': 78}
sorted_students = sorted(student_scores.items(), key=lambda x: x[1], reverse=True)
for student, score in sorted_students:
   print(f"{student}: {score}")

The real power in this snippet comes from the key argument passed to the sorted() function. Without it, the list would be sorted alphabetically by student name. The key provides a custom sorting rule.

  • The expression key=lambda x: x[1] tells sorted() to ignore the first item in each pair (the name) and focus only on the second item (the score).
  • Finally, reverse=True flips the order, arranging the list from the highest score down to the lowest.

Using items() for text analysis with word frequencies

The items() method is also a key part of text analysis, allowing you to convert a dictionary of word counts into a sortable list to find the most common terms.

text = "the quick brown fox jumps over the lazy dog the fox was quick"
word_freq = {}
for word in text.lower().split():
   word_freq[word] = word_freq.get(word, 0) + 1

common_words = sorted(word_freq.items(), key=lambda x: x[1], reverse=True)[:3]
print("Most common words:")
for word, count in common_words:
   print(f"'{word}' appears {count} times")

This code snippet efficiently calculates and displays the most common words in a string. It first builds a frequency map by looping through the text, which has been converted to lowercase to ensure words like 'The' and 'the' are treated as the same.

  • The expression word_freq.get(word, 0) + 1 is a concise way to update counts. It fetches a word's current count or defaults to 0 if the word is new, then increments it.
  • After counting, the code sorts the word-count pairs and uses slicing with [:3] to select just the top three items.

Get started with Replit

Now, turn these techniques into a real tool. Tell Replit Agent to "build a tool that sorts product prices from a dictionary" or "create a word frequency counter that lists the most common words."

Replit Agent writes the code, tests for errors, and deploys your application. Start building with Replit.

Get started free

Create and deploy websites, automations, internal tools, data pipelines and more in any programming language without setup, downloads or extra tools. All in a single cloud workspace with AI built in.

Get started for free

Create & deploy websites, automations, internal tools, data pipelines and more in any programming language without setup, downloads or extra tools. All in a single cloud workspace with AI built in.