Page 182 -
P. 182
all sorted
Either sorting option works with the coach’s data, but let’s use
a copied sort for now to arrange to sort the data on output. You
were to provide four amended print() statements to replace
those at the bottom of your program.
Simply call print(sorted(james))
“sorted()” on the print(sorted(julie))
data BEFORE
you display it on print(sorted(mikey))
screen.
print(sorted(sarah))
Q: What happens to the unsorted data when I use sort()? Q: And there’s no way to get the original data back?
A: For all intents and purposes, it disappears. Python takes a copy, A: No. If the ordering of the original data is important to you, use
sorts it, and then replaces your original data with the sorted version. the sorted() BIF to transform your data into a sorted copy.
Geek Bits
You’ve already seen method chaining, and now it’s time to say
“hello” to function chaining. Function chaining allows you to apply
a series of functions to your data. Each function takes your data,
performs some operation on it, and then passes the transformed
data on to the next function. Unlike method chains, which read
from left to right, function chains read from right to left (just to
keep things interesting).
146 Chapter 5