0
what is wrong in this program unable to get output??
#i am getting an error msg "NameError: free variable 'b' referenced before assignment in #enclosing scope" help me how to resolve it def orginal(n): b=[i for i in n if i not in b] print(b) n=[9,3,9,8,2,8,3,2,5,8] orginal(n)
5 Answers
+ 2
def orginal(n):
b = []
[b.append(i) for i in n if i not in b]
print ("The list after removing duplicates : " , str(b))
n=[9,3,9,8,2,8,3,2,5,8]
orginal(n)
#this works
+ 1
you cannot use b in your conditional statement unless it has already been declared. just declare b first as an empty list.
_____________________________
def orginal(n):
b = []
b=[i for i in n if i not in b]
print(b)
n=[9,3,9,8,2,8,3,2,5,8]
orginal(n)
+ 1
@ethan gallup i tried what u gave but it is not removing duplicates
0
what is b doing in that list comprehension? Have you assigned some value to it before this expression.
0
nice! good work!