Why learn Python ??

M

Mirko Zeibig

Rainer Deyke said the following on 01/16/2004 07:23 PM:
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
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,283
Messages
2,571,405
Members
48,098
Latest member
inno vation

Latest Threads

Top