CSC 161 Lecture Notes - Lecture 8: Edge Case, Eval

16 views4 pages

Document Summary

To make sorting work with our objects, we need to tell sort how the objects should be compared can supply a function to produce the key for an object using . sort(key=) . To sort by gpa, we need a function that takes a student as parameter and returns the student"s gpa. Notice that we didn"t put ()"s after the function name: data. sort(key=use_gpa) this is because we don"t want to call use_gpa, but rather, we want to send use_gpa to the sort. Actually, defining use_gpa was unnecessary: the gpa method in the student class is a function that takes a student as a parameter (formally, self) and returns gpa can use it: data. sort(key=student. gpa. Tuples are used inside the python interpreter to pass around information: . Packing/unpacking are fundamental features of tuples that are used heavily in python, A common data type used these days is a nonsequential collection called a dictionary .

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents