FAQ

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,


Smille

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 11 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedAug 8, '03 at 8:11a
activeAug 13, '03 at 9:57a
posts11
users10
websitepython.org

People

Translate

site design / logo © 2022 Grokbase