0 votes
1 view
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.3k 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 (107k 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
asked Jul 22, 2019 in Python by Eresh Kumar (32.3k points)
0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...