Page 171 -
P. 171
sort the array
Sort the array before
displaying the results
The array is storing the scores in the order they were read from the file.
However, you still need to sort them so that the highest scores appear first.
You could sort the array by comparing each of the elements with each of
the other elements, and then swap any that are in the wrong order. The boxes in the array are
stored in a random order.
boxes
0 1 2 3
boxes
0 1 2 3
By closely examining the array
of boxes, you can sort them by
That looks complicated. Aren‛t arranging the boxes in biggest-
we doing all this to make the to-smallest order.
code simpler and easier to maintain?
I wonder if the array has any built—
in methods that might help...?
Arrays in Python have a whole host of methods that make
many tasks easier.
Let’s see which ones might help.
136 Chapter 4