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__
1.4m articles
1.4m replys
5 comments
57.0k users