So my class is
class Student:
raise_amt = 1.8
no_of_students = 0
def __init__(self, id, name, age, salary):
self.id = id
self.name = name
self.age = age
self.salary = salary
Student.no_of_students+=1
def __repr__(self):
return "Student({}, {}, {}, {})".format(self.id, self.name, self.age, self.salary)
def __str__(self):
return "Student user: {}, name:{}, age:{}".format(self.id, self.name, self.age)
And I have created an object with 3 objects
s1 = Student(10, "Pranav", 21, 1200)
s2 = Student(20, "Pranav", 22, 1500)
s3 = Student(30, "tejas", 22, 5999)
students = []
students.append(s1)
students.append(s2)
students.append(s3)
The sort function given is
students.sort(key = lambda x:x.name)
I WANT TO SORT THE LIST IN SUCH A WAY THAT IF NAMES ARE EQUAL, IT SHOULD THEN CHECK AGE AND IF THAT IS EQUAL ASWELL THEN SALARY
Basically the equivalent of the comparator class in Java