How to delete an element from a list while iterating it in Python?
- by bodacydo
Suppose I have a list of numbers:
L = [1, 2, 3, 4, 5]
How do I delete an element, let's say 3, from the list while I iterate it?
I tried the following code but it didn't do it:
for el in L:
if el == 3:
del el
Any ideas?
Thanks, Boda Cydo.