[Python-3000] Default dict iterator should have been iteritems()

Georg Brandl g.brandl at gmx.net
Tue Sep 4 11:09:07 CEST 2007


Noam Raphael schrieb:

> As I see it, the only reason for the current status is the desire to
> make "x in dict" equivalent to "dict.has_key(x)", since has_key is a
> common operation and "x in" is shorter. But actually "dict.has_key(x)"
> explains exactly what's intended, while "x in dict" isn't really clear
> (for newbies, that is): do you ask whether x is in dict.keys(), or in
> dict.values(), or in dict.items()?

Even if it's true that a loop over items is more common than a loop over keys,
"x in keys" is much more common than "x in items".

In every language there are things that must be learned and remembered.
That dict.__iter__ yields keys is one of them.

(You could present similar arguments that speak in favor of dict.__iter__
yielding values...)

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-3000 mailing list