old vs new iteration protocols (was Re: Booleans, &c)

Alex Martelli aleax at aleax.it
Thu Apr 11 04:52:23 EDT 2002


Aahz wrote:

> In article <C%Xs8.3139$b62.77265 at news1.tin.it>,
> Alex Martelli  <aleax at aleax.it> wrote:
>>
>>With the previous iterator protocol, "for item in somedict:" COULD
>>NOT "work smoothly and seamlessly".  Nor, at all.  Think about it.
> 
> Oh, come on, Alex; with your twisted imagination, I'm sure you can think
> of ways in which a dictionary could be forced to work with the old
> iterator protocol -- it would just be very, very messy.

Twisted imagination, me?  I'm a plodding infantry type and I take this
as a challenge.  How does e.g, somedict[0] return some "first thingy
in somedict" AND at the same time raise KeyError if 0 ain't a key in
somedict, just to start with?  The latter is part of the fundamental
social contract of dictionaries -- the former is part of the old
iteration protocol.


Alex




More information about the Python-list mailing list