list remove

Oleg Broytmann phd at phd.pp.ru
Tue Oct 2 12:34:27 EDT 2001


On Tue, Oct 02, 2001 at 10:30:51AM -0600, steven.smith at LEVEL3.com wrote:
> The python tutorial at
> http://www.python.org/doc/current/tut/node7.html#SECTION00710000000000000000
> 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)
> 
> >>>foo
> [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.

   NEVER, I said NEVER modify the list while running through it!

Oleg.
---- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list