list remove

chajadan python at
Thu Oct 4 07:20:58 CEST 2001

This one really tickled me =)

But I actually was left with a question as well. When you say:

for bar in foo:

is not the first bar [1], so why doesn't the second element get deleted first? rather than being left at the end altogether..??


---------- Original Message ----------------------------------
From: steven.smith at
Date:  Tue, 2 Oct 2001 10:30:51 -0600

>The python tutorial at
>0 has the section more on lists where it gives the function remove(x).  I am
>trying to use this function to delete elements out of my list, but it only
>deletes every other list.
>>>>foo = [1, 2, 3, 4, 5]
>>>>for bar in foo:
>...	foo.remove(bar)
>[2, 4]
>Is this an error on my part, pythons list type or am I misinterpretting what
>remove does?  I have tried this on both 2.1 and 1.5.2.

More information about the Python-list mailing list