i have a list , lets say :
test = [False, False, 2, False, False, False, 3, False, False]
and i want to assign every member of this list to False unless this member is equal to 2
so the result should be :
test = [False, False, 2, False, False, False, False, False, False]
i tried :
test = [False for i in test if i !=2]
but the result was :
[False, False, False, False, False, False, False, False]
and i try to define a function :
def set_False(lst):
for i in lst:
if i != 2:
i = False
return lst
and when i apply :
test = set_False(test)
the result was:
[False, False, 2, False, False, False, 3, False, False]
i can’t use enumerate in the environment where i am putting my code , so any suggestion ?
thanks
It’s
Otherwise, you’re skipping the whole element when it’s equal to 2.