list.pop([i]) and list.remove(x) w/ for loops

Paul Robinson paul.robinson at quantisci.co.uk
Thu Jun 29 07:20:40 EDT 2000


David White wrote:
> 
> I was getting some unexpected behavior when using list.remove(x), wondering if
> someone can tell me what's going on.

All the replies so far seem fairly reasonable, but what about iterating
backwards:

for index in range(len(olist)-1, -1, -1):
    if condition: 
        del olist[index]

Are there any known problems with this idiom...?
Obviously it gets around the problem of duplicating the list.

	Paul.

-----------------------------------
Business Collaborator Team
Enviros Software Solutions
http://www.businesscollaborator.com
-----------------------------------




More information about the Python-list mailing list