[Python-3000] Default dict iterator should have been iteritems() (original) (raw)
Georg Brandl g.brandl at gmx.net
Tue Sep 4 11:09:07 CEST 2007
- Previous message: [Python-3000] Default dict iterator should have been iteritems()
- Next message: [Python-3000] Default dict iterator should have been iteritems()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.haskey(x)", since haskey is a common operation and "x in" is shorter. But actually "dict.haskey(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.
- Previous message: [Python-3000] Default dict iterator should have been iteritems()
- Next message: [Python-3000] Default dict iterator should have been iteritems()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]