Convert Tuple to List

In Python to convert a tuple to a list you just have to use the list() method:

>>> t = (2, 3, 'smith', 8)
>>> list(t)
[2, 3, 'smith', 8]

Converting tuples of tuples to lists of lists

If you have a tuple of tuples you can convert them to lists with list comprehension:

>>> t = ((2, 3), (8, 9), ('sam', 23))
>>> [list(x) for x in t]
[[2, 3], [8, 9], ['sam', 23]]

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top