Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How convert list in tuple???

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
An other question:

How can I convert a list in a tuple?
I tried:
>>> a = ["A","B","C"]
>>> b = tuple(a) #I found this hint on >>>#Traceback (most recent call last):
File &quot;<pyshell#15>&quot;, line 1, in ?
b = tuple(a)
TypeError: object of type 'tuple' is not callable
 
Your glitch is the &quot;=&quot; operator.

>>> a = [&quot;A&quot;,&quot;B&quot;,&quot;C&quot;]
>>> tuple(a)
('A', 'B', 'C')
>>>

a is now a tuple.

Is this what you wanted?
 
I don't know why but know it works in this way...

>>> a = [&quot;A&quot;,&quot;B&quot;,&quot;C&quot;]
>>> b = tuple(a)
>>> print b
('A', 'B', 'C')

Why there's an error in the previous example?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top