Discussion about PEP 234: iterators
Nathaniel Gray
n8gray at caltech.edu.is.my.email.address
Sun Feb 18 02:10:47 EST 2001
Tim Hochberg wrote:
> [snip discussion of consistency of "if thing in dict:"]
>
> Unfortunately, people tend to think of a dictionary as containing keys
> more than they think of it as containing definitions (values). So the form
> you propose is better from that point of view. It's also probably more
> useful in a practical sense as well. It is kind of distressing that it's
> not consistent with the correspondence that's set up between
> keys<->indices and values<->values though.
Hmm... I tend to think of a dictionary as containing values more than keys.
The keys are just there so you can get to the values, right? Others tend
to think dicts contain (key, value) pairs. Everybody has a different
opinion on this one. Rather than supplying an arbitrary default, which
would lead to confusion, how about we let the programmer specify things
explicitly.
How about we make it:
if key in dict.keys():
and
if value in dict.values():
and maybe even
if (key, value) in dict.items():
That way it's perfectly clear what the programmer intended. I think
there's a really good chance of Guido accepting this proposal, and I've
already written a fully backwards-compatible patch. Anybody up for a trip
back in time?
-n8
--
_.~'^`~._.~'^`~._.~'^`~._.~'^`~._.~'^`~._
Nathaniel Gray
California Institute of Technology
Computation and Neural Systems
n8gray <at> caltech <dot> edu
_.~'^`~._.~'^`~._.~'^`~._.~'^`~._.~'^`~._
More information about the Python-list
mailing list