0
0
PythonHow-ToBeginner · 2 min read

Python How to Convert Dictionary Values to List

Use list(your_dict.values()) to convert the values of a dictionary into a list in Python.
📋

Examples

Input{"a": 1, "b": 2, "c": 3}
Output[1, 2, 3]
Input{"name": "Alice", "age": 30, "city": "NY"}
Output["Alice", 30, "NY"]
Input{}
Output[]
🧠

How to Think About It

To convert dictionary values to a list, think about extracting just the values part of the dictionary and then putting them into a list container. Python provides a simple way to get all values using the values() method, which you can then convert to a list with list().
📐

Algorithm

1
Get the dictionary input.
2
Use the dictionary's <code>values()</code> method to get all values.
3
Convert the values view to a list using <code>list()</code>.
4
Return or print the resulting list.
💻

Code

python
my_dict = {"a": 1, "b": 2, "c": 3}
values_list = list(my_dict.values())
print(values_list)
Output
[1, 2, 3]
🔍

Dry Run

Let's trace the dictionary {"a": 1, "b": 2, "c": 3} through the code

1

Get dictionary values

my_dict.values() returns dict_values([1, 2, 3])

2

Convert to list

list(dict_values([1, 2, 3])) becomes [1, 2, 3]

3

Print result

Output is [1, 2, 3]

StepOperationResult
1my_dict.values()dict_values([1, 2, 3])
2list(...) conversion[1, 2, 3]
3print output[1, 2, 3]
💡

Why This Works

Step 1: Extract values

The values() method gets all values from the dictionary as a special view object.

Step 2: Convert to list

Using list() turns the values view into a normal list you can use like any other list.

🔄

Alternative Approaches

List comprehension
python
my_dict = {"a": 1, "b": 2, "c": 3}
values_list = [value for value in my_dict.values()]
print(values_list)
More explicit but longer; useful if you want to filter or transform values.
Using a for loop
python
my_dict = {"a": 1, "b": 2, "c": 3}
values_list = []
for value in my_dict.values():
    values_list.append(value)
print(values_list)
Verbose but clear for beginners; less Pythonic and slower for large dictionaries.

Complexity: O(n) time, O(n) space

Time Complexity

Converting dictionary values to a list requires visiting each value once, so it takes O(n) time where n is the number of items.

Space Complexity

A new list is created to hold all values, so space used is O(n).

Which Approach is Fastest?

Using list(dict.values()) is the fastest and most readable. List comprehension and loops add overhead without benefit here.

ApproachTimeSpaceBest For
list(dict.values())O(n)O(n)Simple and fast conversion
List comprehensionO(n)O(n)When filtering or transforming values
For loop with appendO(n)O(n)Clear step-by-step for beginners
💡
Use list(your_dict.values()) for a quick and clean conversion.
⚠️
Trying to convert the dictionary directly to a list without using values() returns the keys, not the values.