[Python-Dev] if key in dict?

Skip Montanaro skip@mojam.com (Skip Montanaro)
Thu, 13 Apr 2000 08:39:47 -0500 (CDT)


    Ping> I've been quite happy with "if key in dict".  I forget if i
    Ping> already made this analogy when it came up in regard to the issue
    Ping> of supporting a "set" type, but if you think of it like a real
    Ping> dictionary -- when someone asks you if a particular word is "in
    Ping> the dictionary", you look it up in the keys of the dictionary, not
    Ping> in the definitions.

Also, for many situations, "if value in dict" will be extraordinarily
inefficient.  In "in" semantics are added to dicts, a corollary move will be
to extend this functionality to other non-dict mappings (e.g., file-based
mapping objects like gdbm).  Implementing "in" for them would be
excruciatingly slow if the LHS was "value".  To not break the rule of least
astonishment when people push large dicts to disk, the only feasible
implementation is "if key in dict".

-- 
Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/