Remove items from a list

Duncan Booth duncan.booth at invalid.invalid
Thu Sep 9 10:57:29 CEST 2004


PeterAbel at gmx.net (Peter Abel) wrote in 
news:21064255.0409081005.2dadcdb at posting.google.com:

> When you iterate over a list with a for-loop as you do it,
> you get a copy of "each" item of the list. What you're doing
> is deleting this copy, which is bound to the variable *each*.

This explanation is badly wrong.

None of the items in the list is copied, nor are any objects (copied or 
otherwise) being deleted. A new reference is created to each of the items, 
and that reference is deleted either by the 'del' statement, or when each 
is rebound or goes out of scope.

The objects themselves are deleted only when the last reference to the 
object is deleted (which doesn't happen here).



More information about the Python-list mailing list