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

Tim Peters tim.one at home.com
Sun Jan 28 17:43:21 EST 2001


[Nathaniel Gray]
> ...
> 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!" ;^)

None of the above, actually.  I'd say "yes, and its value is probably like
the value it has in the American Heritage Dictionary, which is

    1.Any of several deciduous, coniferous trees of the genus Larix,
      having needlelike leaves clustered on short shoots and heavy,
      durable wood.

    2.The wood of these trees.


    [German Lärche, from Middle High German larche, from
     Latin larix, laric-.]

    Excerpted from The American Heritage Dictionary of the English
    Language, Third Edition Copyright © 1992 by Houghton Mifflin
    Company. Electronic version licensed from Lernout & Hauspie Speech
    Products N.V., further reproduction and distribution restricted
    in accordance with the Copyright Law of the United States. All
    rights reserved.
"

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

For overwhelmingly most people, most of the time, I think it does.  In
common usage, "Peters, Tim" is "in" the Northern Virginia phone book too, a
large dict mapping names to phone numbers.

> Note for thos> 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.

It would be helpful for that purpose, but Ka-Ping Yee has been suggesting it
for years independent of that purpose, and Guido didn't seem to have sets in
mind when he approved it.

    [Eric S. Raymond]
    > Independently of implementation issues about sets, I think this
    > is a damn fine idea. +1.

    [Guido]
    > No chance of a time-machine escape, but I *can* say that I agree
    > that Ping's proposal makes a lot of sense.  This is a reversal of
    > my previous opinion on this matter.  (Take note -- those don't
    > happen very often! :-)
    >
    > First to submit a working patch gets a free copy of 2.1a2 and
    > subsequent releases,

[back to Nathaniel]
> 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?

Even better, we can have both -- except the collections module has to wait
for a volunteer to design and write it, while Thomas already submitted a
working patch for "mucking up dictionaries".

that-lucky-bastard-gets-*all*-the-free-alpha-releases-ly y'rs  - tim





More information about the Python-list mailing list