[Python-Dev] if key in dict?

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Thu, 13 Apr 2000 13:06:57 +0200


now that we have the sq_contains slot, would it make
sense to add support for "key in dict" ?

after all,

    if key in dict:
        ...

is a bit more elegant than:

    if dict.has_key(key):
        ...

and much faster than:

    if key in dict.keys():
        ...

(the drawback is that once we add this, some people might ex-
pect dictionaries to behave like sequences in others ways too...)

(and yes, this might break code that looks for tp_as_sequence
before looking for tp_as_mapping.  haven't found any code like
that, but I might have missed something).

whaddyathink?

</F>