Three Ways to Convert a Tuple to a List in Python
In this tutorial, you will learn how to convert a tuple to a list in Python.
TLDR solution
# list()
tuple_x = (x1, x2, x3, ...)
list_x = list(tuple_x)
# for loop
tuple_x = (x1, x2, x3, ...)
list_x = []
for i in tuple_x:
list_x.append(i)
# list comprehension
tuple_x = (x1, x2, x3, ...)
list_x = [x for x in tuple_x]
Step-by-Step Example
Suppose, you have the following tuple:
fish_tuple = ('salmon', 'pufferfish', 'mackerel', 'shark')
Use the list() Function
The fastest solution: the list() function.
fish_list = list(tuple_x)
print(fish_list)
['salmon', 'pufferfish', 'mackerel', 'shark']
Use a For Loop
The second fastest solution: a for loop.
fish_list = []
for i in fish_tuple:
fish_list.append(i)
Use a For Loop
The second fastest solution: a for loop.
fish_list = []
for i in fish_tuple:
fish_list.append(i)
That's it! You just learned how to convert a Python tuple to a list.