Discussion about PEP 234: iterators

Aahz Maruch aahz at panix.com
Sun Feb 18 11:00:00 EST 2001


In article <96nst0$pe9 at gap.cco.caltech.edu>,
Nathaniel Gray  <n8gray at caltech.edu.is.my.email.address> wrote:
>
>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():

The problem with this is absolutely horrendous speed/memory performance
with any large dictionary.  Your code generates a list AND THEN DOES A
LINEAR SEARCH.  No, no, no, no, no, no, no.  We've already got

if dict.has_key(key):

and

if key in dict:

is a thin layer of sugar-coating designed to create greater usage
equivalence between lists and dicts.  I'm not particularly fond of it,
but it does have the advantage of not being forced to remember whether
has_key() has an underscore in it.
-- 
                      --- Aahz (Copyright 2001 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Why doesn't "Just Say NO" include caffeine, nicotine, alcohol, Prozac,
and Ritalin?  --Aahz



More information about the Python-list mailing list