Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1new_list = sorted(scores) | A.sort() changes the list in place and returns None, so scores becomes None. Use scores.sort() on its own, or scores = sorted(scores). | |
| 2scores.sort() | BMakes a new sorted list and leaves the original scores list unchanged | |
| 3Sort a list from highest to lowest using reverse=True | Csorted() does not change names. It returns a new list that was never saved, so names prints in the old order. Use names = sorted(names) or names.sort(). | |
| 4Sort a list of dictionaries by one value using key= | Dstudents.sort(key=lambda s: s["age"]) | |
| 5scores = scores.sort() | ESorts the scores list itself (in place) and returns None | |
| 6sorted(names) print(names) | Fsorted(scores, reverse=True) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
sorted() and .sort() — sorted(x) returns a new sorted list and leaves x unchanged. x.sort() sorts the list x itself (in place) and returns None. Both accept reverse=True and key= to change the order.ordered = sorted([70, 55, 90])
print(ordered)scores = [70, 55, 90]
scores.sort()
print(scores)names = ['Zed', 'Amy', 'Bo']
names.sort(reverse=True)
print(names)words = ['kiwi', 'fig', 'banana']
print(sorted(words, key=len))people = [{'age': 15}, {'age': 12}]
people.sort(key=lambda p: p['age'])
print(people)