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

Appendix A. appendix: leftovers: The Top Ten Topics (We Didn’t Cover)

Image

We’ve covered a lot of ground, and you’re almost finished with this book. We’ll miss you, but before we let you go, we wouldn’t feel right about sending you out into the world without a little more preparation. We can’t possibly fit everything you’ll need to know into this relatively small chapter. Actually, we did originally include everything you need to know about Python programming (not already covered by the other chapters), by reducing the type point size to .00004. It all fit, but nobody could read it. So we threw most of it away, and kept the best bits for this Top Ten appendix.

#1 List comprehensions

You’ve seen how we can create a list of numbers using the range function in Python, but there is an even more powerful way to construct lists that is similar to the way mathematicians construct sets of numbers. We call them list comprehensions and they can construct lists of any type. Let’s first look at an example with numbers:

Image

Or, how about an example with strings:

Image

Okay, but how does this actually work? Well, essentially a list comprehension creates a list from another list. To see how this works, ...

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