# Arup Guha
# 7/9/2019
# Custom Sorting in Python

# A struct, essentially.
class student():
    def __init__(self, name, id):
        self.name = name;
        self.id = id

def main():

    # Fill my list.
    liststuds = []
    liststuds.append(student("bob",17))
    liststuds.append(student("alice",13))
    liststuds.append(student("alice",19))
    liststuds.append(student("bob",13))

    # Print it.
    for stud in liststuds:
        print(stud.name+" "+str(stud.id))
    print("-------------")

    # This sorts by student id, then name, both doing stable sorts,
    # so final list is sorted by name, ties broken by student id.
    liststuds.sort(key=lambda stud:stud.id);
    liststuds.sort(key=lambda stud:stud.name);

    # New list.
    for stud in liststuds:
        print(stud.name+" "+str(stud.id))
main()
