I have some code which does a lot of "in" on lists containing objects
with no __eq__ defined.
It all goes fast until I add the __lt__() method: then I have a
slowdown comparable to the one I get using the overridden __eq__, while
the __lt__ method is never called.
Someone can explain me why?
I
Maric Michaud spiegò:
> Le Mercredi 14 Juin 2006 22:57, Emanuele Aina a écrit :
> > Here you can see that even with only the __lt__ method it goes 10x
> > slower, but __lt__ is never called as "Foo" is not printed.
>
> No, that is not what it shows. The only thing
Maric Michaud continuò:
> > But I hoped in a more exaustive answer: why python has to do this
> > lookup when the __lt__ method is not involved at all?
>
> It is not the case, that's what my program shows :
>
>
>
> in operator at the beginning of list: 173
> in operator at the end of list: 28249
[EMAIL PROTECTED] dettagliò:
> > Someone can explain me why?
>
> The list's __contains__ method is very simple
[...]
> So if you define "__lt__" in your object then the type gets a richcmp
> function and your == test implicit in the 'in' search always incurs the
> cost of figuring out that "__eq