[Python-Dev] re: for in dict (user expectation poll)
Thomas Wouters
thomas@xs4all.net
Tue, 6 Feb 2001 13:44:47 +0100
On Mon, Feb 05, 2001 at 02:22:50PM -0500, Greg Wilson wrote:
> OK, now here's the hard one. Clearly,
Noshit. I ran into all of this while trying to figure out how to quick-hack
implement it. My brain exploded while trying to grasp all implications,
which is why I've been quiet on this issue -- I'm healing ;-P
> (a) for i in someList:
> has to continue to mean "iterate over the values". We've agreed that:
> (b) for k:v in someDict: means "iterate through the items". (a) looks
> like a special case of (b).
I'm still not sure if I like the special syntax to iterate over
dictionaries. Are we talking about iterators, or about special syntax to use
said iterators in the niche application of dicts and mapping interfaces ? :)
> I therefore asked my colleagues to guess what:
> (c) for x in someDict:
> did. They all said, "Iterates through the _values_ in the dict",
> by analogy with (a).
But how baffled were they when it didn't do what they expected it to do ?
Did they go, 'oh shit, now what' ?
> I then asked, "How do you iterate through the keys in a dict, or
> the indices in a list?" They guessed:
> (d) for x: in someContainer:
Again, how baffled were they when you said it wasn't going to work ? Because
(c) and (d) are just very light syntactic powdered sugar substitutes for
'k:v' where you just don't use one of the two. The extra name binding
operation isn't going to cost you enough to really worry about, IMHO.
--
Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!