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.
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:
Or, how about an example with strings:
Okay, but how does this actually work? Well, essentially a list comprehension creates a list from another list. To see how this works, ...