Python tip: Simplify comparison methods with total_ordering

#Python tip: Don't write all 6 comparison methods! Define __eq__ and __lt__, then add @total_ordering: from functools import total_ordering @total_ordering class C: def __lt__(self, o): ... def __eq__(self, o): ... You get >, >=, <= for free!

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories