M
Mirko Zeibig
Rainer Deyke said the following on 01/16/2004 07:23 PM:
Hm, I think there are similar problems in Python:
--- snip ---
adict = {'foo': 'bar', 'spam': 'ham'}
for key in adict: # has to be adict.keys()
del adict[key]
--- snap ---
This snippet leads to a RuntimeError but the first item will be gone.
Of course, you may use the "older" syntax in this case. ".keys()" will
generate the list of keys once in advance, while the upper example will
call next() each time AFAIK.
Regards
Mirko
--
One thing is that iterators can get invalidated when the container is
modified.
Hm, I think there are similar problems in Python:
--- snip ---
adict = {'foo': 'bar', 'spam': 'ham'}
for key in adict: # has to be adict.keys()
del adict[key]
--- snap ---
This snippet leads to a RuntimeError but the first item will be gone.
Of course, you may use the "older" syntax in this case. ".keys()" will
generate the list of keys once in advance, while the upper example will
call next() each time AFAIK.
Regards
Mirko
--