???? i can`t understand it

Smille Purusa Smille at mail.com
Tue Aug 12 01:18:55 CEST 2003

Enrique wrote:

>>>> a=[1,2,3,4,5]
>>>> for b in a:
> ...  a.remove(b)
> ...
>>>> a
> [2, 4]
Very interesting result but reasonable. If the underlying interpreter uses
a reference or pointer for the job like this:

# psudo codes for python
for(ptr = a.first(); ptr.is_valid(); ++ptr)
     update('b', value(ptr))
     call_method('a', 'remove', get_alue('b'))

ptr may be just an index. So at the first iteration, the first element, '1',
is removed from a. The next time ptr=1, but a has been changed to [2,3,4,5],
so '3' is removed, and so on,


More information about the Python-list mailing list