Thursday, 3 August 2017

Convert list to tuple in Python



I'm trying to convert a list to a tuple.



Most solutions on Google offer the following code:



l = [4,5,6]
tuple(l)



However, the code results in an error message when I run it:




TypeError: 'tuple' object is not callable
How can I fix this problem?



Answer



It should work fine. Don't use tuple, list or other special names as a variable name. It's probably what's causing your problem.



>>> l = [4,5,6]

>>> tuple(l)
(4, 5, 6)

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...