0
0
PythonHow-ToBeginner · 2 min read

Python How to Convert Tuple to List Easily

You can convert a tuple to a list in Python by using the list() function like this: list(your_tuple).
📋

Examples

Input(1, 2, 3)
Output[1, 2, 3]
Input('apple', 'banana', 'cherry')
Output['apple', 'banana', 'cherry']
Input()
Output[]
🧠

How to Think About It

To convert a tuple to a list, think of the tuple as a fixed collection of items and the list as a flexible collection. Using the list() function, you create a new list that contains the same items as the tuple, allowing you to modify the collection if needed.
📐

Algorithm

1
Get the tuple you want to convert.
2
Use the <code>list()</code> function and pass the tuple as an argument.
3
Store the result in a new variable or overwrite the old one.
4
Return or use the new list as needed.
💻

Code

python
my_tuple = (1, 2, 3)
my_list = list(my_tuple)
print(my_list)
Output
[1, 2, 3]
🔍

Dry Run

Let's trace converting the tuple (1, 2, 3) to a list.

1

Start with tuple

my_tuple = (1, 2, 3)

2

Convert tuple to list

my_list = list(my_tuple) # my_list becomes [1, 2, 3]

3

Print the list

print(my_list) outputs [1, 2, 3]

StepValue of my_list
After conversion[1, 2, 3]
💡

Why This Works

Step 1: Using list() function

The list() function takes any iterable, like a tuple, and creates a new list containing the same elements.

Step 2: Creating a new list

This conversion creates a new list object, so you can change it without affecting the original tuple.

🔄

Alternative Approaches

Using list comprehension
python
my_tuple = (1, 2, 3)
my_list = [item for item in my_tuple]
print(my_list)
This method is more flexible if you want to transform items during conversion but is less concise.
Using unpacking operator
python
my_tuple = (1, 2, 3)
my_list = [*my_tuple]
print(my_list)
This uses unpacking to create a list; it is concise and readable but less common for beginners.

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

Time Complexity

Converting a tuple to a list requires copying each element once, so it takes linear time proportional to the number of elements.

Space Complexity

A new list is created with the same elements, so it uses linear extra space equal to the tuple size.

Which Approach is Fastest?

Using list() is the fastest and most readable method; alternatives like list comprehension or unpacking are slightly slower but offer flexibility.

ApproachTimeSpaceBest For
list()O(n)O(n)Simple and fast conversion
List comprehensionO(n)O(n)Transforming items during conversion
Unpacking operatorO(n)O(n)Concise syntax, readability
💡
Use list(your_tuple) for a quick and clear conversion from tuple to list.
⚠️
Trying to change a tuple directly without converting it first, which causes errors because tuples are immutable.