list to tuple and vice versa

Ben Finney ben+python at
Sun Oct 18 05:33:17 CEST 2009

Jabba Laci <jabba.laci at> writes:

> Hi,
> I have some difficulties with list -> tuple conversion:
> t = ('a', 'b')
> li = list(t)   # tuple -> list, works
> print li   # ['a', 'b']
> tu = tuple(li)   # list -> tuple, error
> print tu   # what I'd expect: ('a', 'b')

Works fine for me:

    Python 2.5.4 (r254:67916, Sep 26 2009, 11:00:02) 
    [GCC 4.3.4] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> t = ('a', 'b')
    >>> li = list(t)
    >>> print li
    ['a', 'b']
    >>> tu = tuple(li)
    >>> print tu
    ('a', 'b')

> The error message is: "TypeError: 'tuple' object is not callable".

Nothing in your example code is calling a tuple object. This makes me
suspect that what you showed us is not what you actually tried.

You might want to try the above session yourself and paste the resulting
session *literally* (rather than re-typing) as I did above, so we can
see what you're seeing.

 \           “If you ever fall off the Sears Tower, just go real limp, |
  `\     because maybe you'll look like a dummy and people will try to |
_o__)                catch you because, hey, free dummy.” —Jack Handey |
Ben Finney

More information about the Python-list mailing list