list remove

chajadan python at chajadan.net
Thu Oct 4 01:20:58 EDT 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..??

--chajadan

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

>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.
>
>Thanks.
>Steve
>
>-- 
>http://mail.python.org/mailman/listinfo/python-list
>




More information about the Python-list mailing list