O'Reilly logo

Head First Learn to Code by Eric Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. 8 recursion and dictionaries: Beyond Iteration and Indices

Image

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.

Image

Before we get there, though, let’s take a simple problem and think it through the way we have throughout this book. For ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required