DEV Community

Discussion on: Daily Challenge #121 - Who has the most money?

hectorpascual profile image
Héctor Pascual

My Python attempt :

Using total_ordering decorator from func_tools, which only requires two implementations of the comparison methods.

from functools import total_ordering

class Student:

  def __init__(self, name, fives, tens, twenties): = name
    self.fives = fives
    self.tens = tens
    self.twenties = twenties
    # Added new property = self.fives*5 + self.tens*10 + self.twenties*20

  def __eq__(self, other):
    return ==
  def __lt__(self, other):
    return <

st1 = Student('Héctor',1,7,3)
st2 = Student('Albert',5,4,3)
st3 = Student('Jordi',1,4,3)

students = [st1, st2, st3]