Chapter 6. 4, part 2, sorting and nested iteration: Putting Some Order in Your Data
in which we return to the lists and add some superpowers
Sometimes the default ordering of your data doesn’t cut it. You’ve got that list of high scores on 80s arcade games, but you really need it sorted alphabetically by game name. Then there’s that list of the number of times your coworkers have stabbed you in the back—it would be nice to know who’s at the top of that list. To do that, though, we need to learn how to sort data, and to do that we’ll need to explore some algorithms that are a little more involved than the ones we’ve seen so far. We’re also going to have to explore how nested loops work as well as think a little about the efficiency of the code we’re writing. Come on, let’s take that computational thinking up a level!
Cubicle conversation
Frank: Well, it doesn’t sound bad, but how do we do it?
Judy: We’ve been coming up with some great algorithms, so I’m sure we can tackle sorting.
Joe: Actually, sorting algorithms are a topic some computer scientists spend their entire careers researching. They’re not something we should “come up with,” but rather we need to research the ...
Get Head First Learn to Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.