l
is a list that I want to explore in order to suppress some items. The function do.i.want.to.suppres.i
returns TRUE or FALSE in order to tell me whether I want the suppression. The details of this function is not important.
I tried this:
l = [1,4,2,3,5,3,5,2]
for i in l:
if do.i.want.to.suppress.i(i):
del i
print l
but l
does not change! So I tried
l = [1,4,2,3,5,3,5,2]
for position,i in enumerate(l):
if do.i.want.to.suppress.i(i):
del l[position]
But then the problem is that the position does not match the object i
as l
get modified during the loop.
I could do something like this:
l = [1,4,2,3,5,3,5,2]
for position,i in enumerate(l):
if do.i.want.to.suppress.i(i):
l[position] = 'bulls'
l = [x for x in l if x!='bulls']
But I guess there should have a smarter solution. Do you have one?