What methods need to be overridden/implemented when making user-defined classes sortable and/or hashable in python?
What are the gotchas to watch out for?
I
There are a few ways of marking your object sortable. First - rich comparison, defined by a set of functions:
object.__lt__(self, other)
object.__le__(self, other)
object.__eq__(self, other)
object.__ne__(self, other)
object.__gt__(self, other)
object.__ge__(self, other)
Also it is possible to define only one function:
object.__cmp__(self, other)
And the last should be defined if you want to define custom __hash__ function. See the doc.