Python set to list Python set to list python python

Python set to list


Your code does work (tested with cpython 2.4, 2.5, 2.6, 2.7, 3.1 and 3.2):

>>> a = set(["Blah", "Hello"])>>> a = list(a) # You probably wrote a = list(a()) here or list = set() above>>> a['Blah', 'Hello']

Check that you didn't overwrite list by accident:

>>> assert list == __builtins__.list


You've shadowed the builtin set by accidentally using it as a variable name, here is a simple way to replicate your error

>>> set=set()>>> set=set()Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: 'set' object is not callable

The first line rebinds set to an instance of set. The second line is trying to call the instance which of course fails.

Here is a less confusing version using different names for each variable. Using a fresh interpreter

>>> a=set()>>> b=a()Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: 'set' object is not callable

Hopefully it is obvious that calling a is an error


before you write set(XXXXX)you have used "set" as a variablee.g.

set = 90 #you have used "set" as an object……a = set(["Blah", "Hello"])a = list(a)