as you can seepython gives us an error message because it does not know how our student objects should be ordered if you think about itthat makes sense we have not defined any implicit ordering for studentsand we might want to arrange them in different order for different purposes in this examplewe want them ranked by gpain another contextwe may want them in alphabetical order in data processingthe field on which records are sorted is called key to put the students in alphabetical orderwe would use their name as the key for our gpa problemobviouslywe want the gpa to be used as the key for sorting the students the built-in sort method gives us way to specify the key that is used when sorting list by supplying an optional keyword parameterkeywe can pass along function that computes key value for each item in the list sort(keythe key_function must be function that takes an item from the list as parameter and returns the key value for that item in our casethe list item will be an instance of studentand we want to use gpa as the key here' suitable key functiondef use_gpa(astudent)return astudent gpa(as you can see this function simply uses the gpa method defined in the student class to provide the key value having defined this little helper functionwe can use it to sort list of students with call to sort data sort(key=use_gpaan important point to notice here is that did not put parentheses on the function name (use_gpa() do not want to call the function ratheri am sending use_gpa to the sort methodand it will call this function anytime it needs to compare two items to see what their relative ordering should be in the sorted list it' often useful to write this sort of helper function to provide keys for sorting listhoweverin this particular casewriting an additional function is not really necessary we have already written function that computes the gpa for studentit' the gpa method in the student class if you go back and look at the definition of that methodyou'll see that it takes single parameter (selfand returns the computed gpa since methods are just functionswe can use this as our key and save us the trouble of writing the helper in order to use method as standalone functionwe just need to use our standard dot notation data sort(key=student gpathis snippet says to use the function/method called gpa defined in the student class think we now have all the components in place for our program here' the completed codegpasort py program to sort student information into gpa order