Back

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

In python 2.6, When I tried to convert a set to a list using the below code:

first_list = [1,2,3,4]

my_set=set(first_list)

my_list = list(my_set)

I'm getting error like this:

Traceback (most recent call last):

  File "<console>", line 1, in <module>

TypeError: 'set' object is not callable

Can anyone suggest to me some ways to fix this?

1 Answer

0 votes
by (26.4k points)

If you check the type of my_set, it's already a list

type(my_set)

>>> <type 'list'>

Are you expecting like this:

my_set = set([1,2,3,4])

my_list = list(my_set)

print my_list

>> [1, 2, 3, 4] 

This is the output of your last comment

>>> my_list = [1,2,3,4]

>>> my_set = set(my_list)

>>> my_new_list = list(my_set)

>>> print my_new_list

[1, 2, 3, 4]

I'm still thinking if you've done like this:

>>> set=set()

>>> set([1,2])

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: 'set' object is not callable

Are you Interested to learn python? Come and join Python certification course to gain more knowledge in python. 

Related questions

0 votes
2 answers
asked Oct 3, 2019 in Python by Tech4ever (20.3k points)
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)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...