Remove items from a list
Peter Abel
PeterAbel at gmx.net
Thu Sep 9 17:25:35 EDT 2004
Duncan Booth <duncan.booth at invalid.invalid> wrote in message news:<Xns955F64A72538Cduncanrcpcouk at 127.0.0.1>...
> 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).
This explanation is correct.
My english is not yet good enough to enunciate in that brilliant way
you did but I promise I'll work hard on it (mea culpa) :-)
Peter
More information about the Python-list
mailing list