finding object using IS instead of ==
Andrew Bennetts
andrew-pythonlist at puzzling.org
Thu Aug 28 00:48:52 EDT 2003
On Wed, Aug 27, 2003 at 09:35:46PM -0700, Mark Hahn wrote:
> Clarification: Is there a FASTER way that takes advantage of the IS
> equivalence than using the available == method. I assume the == method does
> a linear search, except for a dict key lookup, which is not what I'm talking
> about.
>
> Obviously if two references are the same object (IS equivalent) then they
> are == also so you could find based on == and then check for IS, but I want
> something faster.
Actually, (x != y) doesn't necessarily imply that (x is not y):
>>> class NeverEqual:
... def __eq__(self, other):
... return False
...
>>> ne = NeverEqual()
>>> ne == ne
False
>>> ne is ne
True
I'm not sure how much this matters to you, though :)
-Andrew.
More information about the Python-list
mailing list