[Python-3000] Spooky behavior of dict.items() and friends
Ivan Krstić
krstic at solarsail.hcs.harvard.edu
Wed Apr 2 20:57:49 CEST 2008
On Apr 2, 2008, at 11:36 AM, Guido van Rossum wrote:
> I predict that list(x.keys()) will remain a rarity (except in
> code converted by 2to3). However sorted(x.keys()) will become a
> well-known idiom, and it's a much better one than the old idiom
> keys = x.keys()
> keys.sort()
> which doesn't led itself easily to use in an expression.
Is there a particular rationale describing the use of function calls
vs. object properties in core Python?
When I see a function call required for something that could be
conveniently expressed as a property, it generally tells me "I'm
computing something. It might be expensive, and if you call me again,
I'll have to recompute."
This made sense with .keys() in 2.x, but is not true in 3.0. Is there
a good reason besides compatibility to keep the parentheses there?
sorted(x.keys)
has a nice ring to it. Cheers,
--
Ivan Krstić <krstic at solarsail.hcs.harvard.edu> | http://radian.org
More information about the Python-3000
mailing list