Python Program to Convert Tuple to List
You can convert a tuple to a list in Python by using the
list() function like this: my_list = list(my_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. You want to create a new collection that can be changed, so you use the built-in
list() function to make a new list with the same items.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.4
Return or print the new list.Code
python
my_tuple = (1, 2, 3) my_list = list(my_tuple) print(my_list)
Output
[1, 2, 3]
Dry Run
Let's trace the example tuple (1, 2, 3) through the code
1
Define the 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) # Output: [1, 2, 3]
| Step | Variable | Value |
|---|---|---|
| 1 | my_tuple | (1, 2, 3) |
| 2 | my_list | [1, 2, 3] |
| 3 | output | [1, 2, 3] |
Why This Works
Step 1: Tuple is immutable
A tuple cannot be changed after creation, so to modify the data, we need a list which is mutable.
Step 2: Using list() function
The list() function takes any iterable like a tuple and creates a new list with the same elements.
Step 3: Result is a list
The new variable holds a list that can be changed, unlike 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 manually copies each item into a new list; it is more verbose but shows the process explicitly.
Using unpacking with list constructor
python
my_tuple = (1, 2, 3) my_list = list(*my_tuple) print(my_list)
This uses unpacking to pass elements to list; it is less common and more complex than direct list() conversion.
Complexity: O(n) time, O(n) space
Time Complexity
The list() function iterates over each element of the tuple once, so the time grows linearly with the number of elements.
Space Complexity
A new list is created with the same number of elements, so space usage is also linear.
Which Approach is Fastest?
Using list() is the fastest and simplest method compared to list comprehension or unpacking.
| Approach | Time | Space | Best For |
|---|---|---|---|
| list() function | O(n) | O(n) | Simple and fast conversion |
| List comprehension | O(n) | O(n) | Explicit copying, educational |
| Unpacking with list() | O(n) | O(n) | Less common, more complex |
Use the built-in
list() function for a quick and clean conversion from tuple to list.Trying to change a tuple directly instead of converting it to a list first.