"in" for dicts (was: Python 2.1 function attributes)

Nathaniel Gray n8gray at caltech.edu
Sun Jan 28 17:01:11 EST 2001


Tim Peters wrote:
> 
> [Robin Becker]
> > yes I figured it was a bit funny, but nastier things are proposed and
> > aren't laughed off.
> 
> By whom?  They're *scowled* off by Guido, and that's all that counts in the
> end.
> 
> > -why don't we have $ and @ and \ operators-ly yrs-
> 
> Because so far, Guido hates them.  This is usually something you can count
> on for life.  But, e.g., in the past he disliked the idea of being able to
> say
> 
>     if key in dict:
> 
> instead of
> 
>     if dict.has_key(key):
> 
> because in the first form it's not 100% clear whether you're asking if key
> is in dict.keys() or dict.values() or dict.items().  In a once-per-decade
> reversal, he changed his mind about that last week, and Thomas Wouters
> graciously implemented it for 2.1.
> 
> It's a nice addition.  People will complain about it, and some bitterly, but
> so it goes.
> 
> when-people-disagree-not-everyone-gets-what-they-want-ly y'rs - tim

Funny, I was going to bring this up in this thread as a bad idea that
actually _is_ going into Python 2.1.  Let me then be the first to
complain about it (perhaps not bitterly).

If I was to ask you, "Tim, is 'larch' in Webster's dictionary?" would
you reply, "Yes, it's under 'L'", or would you reply, "No, there's no
'larch' section, just A,B,C,D,..."?

(I know you'd _actually_ reply "Look it up yourself!" ;^)

"in" just doesn't imply "has_key" for dictionaries.  

Note for those who don't read python-dev:  It seems this "feature" is
being added to facilitate the use of dictionaries as sets, so you can
say:
	if something in my_set:
		something.foobar()
and the like.

Couldn't we just have a collections module for Python that gave us a set
class (and all the other wonders that CS can produce) without mucking up
dictionaries?

-- 
_.~'^`~._.~'^`~._.~'^`~._.~'^`~._.~'^`~._
             Nathaniel Gray
   California Institute of Technology
     Computation and Neural Systems
_.~'^`~._.~'^`~._.~'^`~._.~'^`~._.~'^`~._



More information about the Python-list mailing list