Menu Close

How To Convert a Tuple To a List in Python?

how to convert a tuple to a list in python

In this article, we will see how to convert a tuple to a list in Python with the help of various examples.
In our previous tutorials, we have seen lots of Python programs that are very useful for you. In this guide, we demonstrate to you, how you can convert python tuple to list with the help of
various examples, so that you don’t have any confusion regarding how to convert a tuple to a list in Python.

But, before further this article, let’s see a little about Python tuple and list.

What is Python Tuple ?

A tuple is a core data structure in Python that stored multiple items in an ordered way. Python tuple is ordered, immutable or unchangeable, and also it is able to store duplicate values.
Python tuple always starts and ends with a circular bracket ( ). As you can see below example.

Example

tpl = ("Python", "Machine Learning", "Data Science", "Data Analyst", "Data Analyst")

What is Python List ?

Python list is also a core data structure that stores multiple items in a single variable. Python tuple always starts and ends with square brackets [ ]. Python tuple is ordered, changeable, and also allows duplicate items.

Example

lst = ["Python", "Machine Learning", "Data Science", "Data Analyst", "Data Analyst"]

Now, it’s time to see elegant ways to convert a tuple to a list in Python.

How to convert tuple to list in Python?

Here we will see three examples to convert Python tuple to list using various examples.

Using list() function

Here we will convert Python tuple to list using python built-in list() function.

Example: Python program to convert tuple to list


# tuple
tpl = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
# convert into list
result = list(tpl)
print(result)

Output

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Using for loop

Here we will use Python for loop to convert tuple to list in Python.

Example: Python program to convert tuple to list


# Using the for loop
tpl = ("Python", "Machine Learning", "Data Science", "Data Analyst", "Data Analyst")
result = []
for i in tpl:
    result.append(i)
print(result)

Output

['Python', 'Machine Learning', 'Data Science', 'Data Analyst', 'Data Analyst']

Using list comprehension

list comprehension is the best and concise way to create a list in Python.

Example: Python program to convert tuple to list


tpl = ("Python", "Machine Learning", "Data Science", "Data Analyst")
# Using list comprehension
result = [i for i in tpl]
print(result)

Output

['Python', 'Machine Learning', 'Data Science', 'Data Analyst']
Python Tutorials

Conclusion

So, here we have seen all about how to convert a tuple to a list in Python using various ways. As a developer, you might be required to convert the python tuple t list, Then you can follow all the above processes.

I hope this article will helpful for you. If you like this article, please share and keep visiting for further Python tutorials.

Ref:- Click Here

Thanks for reading…

Previous Article
Next Article

Related Posts