[Python-Dev] object equality vs identity, in and dicts idioms and speed

Samuele Pedroni Samuele Pedroni" <pedroni@inf.ethz.ch
Thu, 3 Jan 2002 17:43:57 +0100


Hi,

[Ok this is maybe more a comp.lang.python thing
but ...]

If I'm correct
dictionaries are based on equality and so the "in" operator.

AFAIK if I'm interested in a dictionary working on identity
I should wrap my objects ...

Now what is the fastest idiom equivalent to:

obj in list

when I'm interested in identity (is) and not equality?

That was the comp.lang.python part, now
my impression is that in any case when I'm interested
in identity and not equality I have to workaround,
that means I will never directly have the performace of the
equality idioms. Although my experience say that the
equality case is the most common, I wonder whether
some directy support for the identity case isn't worth,
because it is rare but typically then you would like some
speed. [Yes, I have some concrete context but this is long
so unless strictly requested ...]

Am I missing something? Opinions.

regards.