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

Aahz aahz at pythoncraft.com
Thu Apr 11 21:15:04 EDT 2002


In article <b9ct8.6406$vF6.199796 at news2.tin.it>,
Alex Martelli  <aleax at aleax.it> wrote:
>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.

<blink>  You're right, never mind.  I was getting things confused in my
head.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"I disrespectfully agree."  --SJM



More information about the Python-list mailing list