I feel this question must have been asked before but I could not find an answer.
Suppose I want to implement a Python class whose objects are sortable with sorted(). Do I have to reimplement all methods like __lt__(), __gt__(), etc.? What is the bare minimum? In other words, which method(s) does sorted() call for sorting?
Per the documentation:
So you only need to define
def __lt__(self,other):for your class.Also see the Sorting HOW-TO which says near the bottom: