Best solution (Re: Discussion about PEP 234: iterators)
stephen_purcell at yahoo.com
Tue Feb 20 08:57:34 CET 2001
Huaiyu Zhu wrote:
> >- make 'dict.keys' return the proxy object, which is
> > callable. Make proxy.__call__() return an actual
> > list from the proxy so dict.keys() works as before.
> > So cute I'm ashamed I even thought of it.
> What a bright idea! This is the best solution I've seen so far. I'm
> surprised no one has commented on this yet. So let me spell it out to
> generate more interest.
> With this proposal, all of these work as expected
> for k in dict.keys:
> for k, v in dict.items:
> for v in dict.values:
> without creating extra list. And all of these work as expected
> if k in dict.keys:
> if k, v in dict.items:
> if v in dict.values:
I love it. Where do I vote? :-)
This is *much* nicer looking than the peculiar new ':' syntax.
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Get servlets at http://pyserv.sourceforge.net/
"Even snakes are afraid of snakes." -- Steven Wright
More information about the Python-list