[Python-3000] Spooky behavior of dict.items() and friends

Guido van Rossum guido at python.org
Wed Apr 2 21:26:08 CEST 2008


We went over this a few years ago when we first reviewed this design
from every POV. We decided that .keys() has been ingrained in the
collective mind of Python users for such a long time that it would be
a mistake to change it.

On Wed, Apr 2, 2008 at 11:57 AM, Ivan Krstić
<krstic at solarsail.hcs.harvard.edu> wrote:
> 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
>
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list