Rainie Hu
Rainie Hu

Reputation: 71

How to convert a tuple to a list of tuple?

For example I have a tuple (1,2,3), how to convert it into [(1,2,3)]? I tried list method but it seems doesn't work.

l = (1,2,3) -> l =[(1,2,3)]

Upvotes: 2

Views: 87

Answers (4)

R__raki__
R__raki__

Reputation: 975

Create an empty list and append tuple to it.

>>>t = (1,2,3)
>>>a = []
>>>a.append(t)
>>>a
[(1,2,3)]
>>>

Upvotes: 0

Mayur Koshti
Mayur Koshti

Reputation: 1862

>>> l = (1,2,3)
>>> print list([l])

Upvotes: 0

Diogo Martins
Diogo Martins

Reputation: 937

l_tuple = (1, 2, 3)
l_list = [l_tuple]
l_list_items = list(l_tuple)

>>> print l_list
[(1, 2, 3)]

>>> print l_list_items
[1, 2, 3]

Not that there is a difference between using the square braces and the list() function to construct your list.

Upvotes: 0

sunhs
sunhs

Reputation: 401

Just put the tuple into a list.

l = [(1, 2, 3)]

Upvotes: 5

Related Questions