Reputation: 68466
I have a collection (list) of objects. I want to be able to sort the objects without having to provide a callback (lambda function) to sorted()
but instead, by implementing functions that could be used to ascertain strict (in)equality between objects of the same type - ala C++.
The __eq__()
function implemented on a class allows equality checks. I can't seem to find any similar functions to implement <
and >
How may I implement this in Python?
Upvotes: 0
Views: 238
Reputation: 10970
http://docs.python.org/reference/datamodel.html#basic-customization
You're looking for
__lt__() and __gt__()
(it's down just a tad under that link).
Upvotes: 1