I have the for-loop:
L=[1,2,3,4]
I want, that the code below works:
for i in range(1,len(L)):
if i%2==0:
L.remove(L[i])
How can I do this? Many thanks.
I have the for-loop:
L=[1,2,3,4]
I want, that the code below works:
for i in range(1,len(L)):
if i%2==0:
L.remove(L[i])
How can I do this? Many thanks.
So you want even indexed elements? Comprehensions are your friend.
L = [e for i,e in enumerate(L) if i % 2]