Chapter 9. 8 recursion and dictionaries: Beyond Iteration and Indices
It’s time to take your computational thinking up a notch. And this is the chapter to do it: we’ve been happily coding along with an iterative style of programming—we’ve created data structures like lists and strings and ranges of numbers, and we’ve written code to compute by iterating over them. In this chapter we’re going to look at the world differently, first in terms of computation, and then in terms of data structures. Computationally we’ll look at a style of computing that involves writing code that recurs, or calls itself. We’ll expand the kinds of data structures we can work with by looking at a dictionary-like data type that is more like an associative map than a list. We’ll then put them together and cause all kinds of trouble. Be forewarned: these topics take a while to settle into your brain, but the effort is going to pay off in spades.
A different way to compute
It’s time for some mind-bending activity—you’ve been thinking about the same, iterative style of programming for too long. So let’s expose your brain to a totally different way of thinking about solving problems.
Before we get there, though, let’s take a simple problem and think it through the way we have throughout this book. For ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access