Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (20.3k points)

How can I convert a set to a list in Python? Using

a = set(["Blah", "Hello"])

a = list(a)

doesn't work. It gives me:

TypeError: 'set' object is not callable

2 Answers

0 votes
by (40.7k points)

Your code will 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']

Note that you should not overwrite list by accident:

>>> assert list == __builtins__.list

0 votes
by (106k points)

It is working fine in my case, you should check that you didn't overwrite list.

image

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 22, 2019 in Python by Eresh Kumar (45.3k points)

Browse Categories

...