a = [1, 2, 3, 4, 5, 6, 7] for i in range(len(a)-1, -1, -1): a.pop(i)Which correctly removes all items from the list. The only problem is that it seems somewhat silly; there's no way that's the "proper" way to do this.
a = [1, 2, 3, 4, 5, 6, 7] for pos, number in enumerate(a): a.pop(pos)will only delete some items.
Posts
Should remove every item. Modify f(x) to return false for items you want to remove and voila.
Here's why enumerating doesn't work, from here:
A better example:
And, yes, I know why enumerate doesn't work; I'm just looking for something that does work.