What is the standard way of making a class comparable in Python 3? (For example, by id.)
To make classes comparable, you only need to implement __lt__ and decorate the class with functools.total_ordering. You should also provide an __eq__ method if possible. This provides the rest of the comparison operators so you don't have to write any of them yourself.
__lt__
functools.total_ordering
__eq__
2.1m questions
2.1m answers
60 comments
57.0k users