sourabh280289
sourabh280289

Reputation: 11

python - converting a set to a list

I am using python 3.4.5 to convert a set into a list The code I have used is as follow :

 def test(): 
        a = {1,2,3,4,5} 
        b = list(a) 

However, I get the following error :

Traceback (most recent call last):
  File line 73, 
    b = list(a) 
UnboundLocalError: local variable 'list' referenced before assignment

Can I get some guidance as to how to resolve this ? is there some library that I should import to convert a set to a list ?

Upvotes: 0

Views: 774

Answers (1)

jsub
jsub

Reputation: 150

The problem is in your error:

Traceback (most recent call last):
  File line 73, 
    b = list(a) 
UnboundLocalError: local variable 'list' referenced before assignment

You named list as a variable or a function before.

Don't use list for your own variables or functions since it's the name of a built-in Python function.

Upvotes: 1

Related Questions