deleting elements from a list in a for loop
flupke
flupke at nonexistingdomain.com
Fri Oct 29 10:48:26 EDT 2004
More information about the Python-list mailing list
Fri Oct 29 10:48:26 EDT 2004
- Previous message (by thread): Python AST as XML
- Next message (by thread): deleting elements from a list in a for loop
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Pierre Barbier de Reuille wrote: > Hi ! > > Indeed, you cannot erase elements in a list you're iterating on ! > a possibility could be : > > to_delete = [] > for i in xrange(len(el)): > if condition: > to_delete.insert(0, i) > for i in to_delete: > del el[i] > > That should work fine ... > > flupke a écrit : Thanks, that works great! Benedict
- Previous message (by thread): Python AST as XML
- Next message (by thread): deleting elements from a list in a for loop
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list