class Student:

    def __init__(self, name, grade, age):
        self.name = name
self.grade = grade
self.age = age

def __repr__(self):
    return repr((self.name, self.grade, self.age))
student_objects = [Student('john', 'A', 15), Student('jane', 'B', 12),
    Student('dave', 'B', 10)]
print(student_objects)
student_objects.sort(key=attrgetter('age'))
How to sort dictionaries of objects by attribute value in python?