text: # Sort objects of user defined classes #
  
  from functools import total_ordering
  
  
  @total_ordering
  class Player:
      def __init__(self, name, points, time_spent):
          self.name = name
          self.points = points
          self.time_spent = time_spent
  
      def __lt__(self, object):
          if self.points < object.points:
              return True
          elif self.points == object.points:  # if equal, sort by time_spent
              return True if self.time_spent < object.time_spent else False
          else:
              return False
  
      def __eq__(self, object):
          return all((self.name == object.name,
                      self.points == object.points,
                      self.time_spent == object.time_spent))
  
      def __repr__(self):
          return f"{self.name}: {self.points} points in {self.time_spent} seconds"
  
  
  # ------------------
  # Example of sorting
  
  p1 = Player("John", 33, 1200)
  p2 = Player("Mike", 66, 1200)
  p3 = Player("Peter", 33, 900)
  
  players = [p1, p2, p3]
  # [John: 33 points in 1200 seconds,
  #  Mike: 66 points in 1200 seconds,
  #  Peter: 33 points in 900 seconds]
  
  players.sort()
  
  players
  # [Peter: 33 points in 900 seconds,
  #  John: 33 points in 1200 seconds,
  #  Mike: 66 points in 1200 seconds]
  
  # -------------------
  # Example of equality
  
  p1 == p2  # False
  p2 == p3  # False
  p2 == p2  # True
  