Comparable classes in Python 3

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.

Leave a Comment