Question: For quite a bit of time now I have been trying to figure out a way to loop through a list and remove the current item that I'm at. I can't seem to get this working as I would like it to. It loops just 1 time through, but I wanted it to loop 2 times. When I remove the removal line - it loops 2 times.

```
a = [0, 1]
for i in a:
    z = a
    print z.remove(i)

```

The output:

```
[1]

```

The output that I was expecting:

```
[1] 
[0]

```

Answer: 
It is bad practice modify a list while you're looping through it†. Create a copy of the list:

```
oldlist = ['a', 'b', 'spam', 'c']
newlist = [x for x in oldlist if x != 'spam']

```

To modify the original list, write the copy back in-place with a slice assignment:

```
oldlist[:] = [x for x in oldlist if x != 'spam']

```

† For a gist of why this might be bad practice, consider the implementation details of what goes on with the *iterator* over the sequence when the sequence changes during iteration. If you've removed the current item, should the iterator point to the next item in the original list or to the next item in the modified list? What if your decision procedure instead removes the *previous* (or *next*) item to the current?
The problem is that you're modifying `a` with `remove` so the loop exits because the index is now past the end of it.