[Tutor] lazily decorated sort
eryksun at gmail.com
Fri Sep 28 22:50:43 CEST 2012
On Fri, Sep 28, 2012 at 3:34 PM, Peter Otten <__peter__ at web.de> wrote:
>> Also, as far as I can see in the code, implementing "total_ordering"
>> is unnecessary for sorting. One only needs to implement __lt__. It's
>> used by binarysort() to test the pivot via the IFLT/ISLT macros:
> I smell danger. I really don't like having a class lying around that
> partially implements ordering and may fail where you least expect it.
I don't know; they're just utility objects used for sorting, which
only cares about __lt__. On the other hand, Python 3 enforces a sanity
check if you implement __eq__ without __hash__. So now you have
objects that can't be used in sets or as dict keys. Not that this
matters. ;) Anyway, it's not hurting. I just thought I'd make the
suggestion to spare you the [small] effort of implementing __eq__ on
something like this.
More information about the Tutor