The list comprehension, though, and related functional programming tools like map
and filter, will generally run faster than a for loop today (perhaps even twice as fast)—
a property that could matter in your programs for large data sets. Having said that,
though, I should point out that performance measures are tricky business in Python
because it optimizes so much, and performance can vary from release to release.
A major rule of thumb in Python is to code for simplicity and readability first and worry
about performance later, after your program is working, and after you’ve proved that
there is a genuine performance concern. More often than not, your code will be quick
enough as it is. If you do need to tweak code for performance, though, Python includes
tools to help you out, including the time and timeit modules and the profile module.
You’ll find more on these later in this book, and in the Python manuals.