finding object using IS instead of ==

Mark Hahn mark at hahnca.com
Thu Aug 28 01:17:04 EDT 2003


Now that is just plain evil!

"Andrew Bennetts" <andrew-pythonlist at puzzling.org> wrote in message
news:mailman.1062046190.2338.python-list at python.org...
> 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