List comprehensions
Let's look at list comprehensions
List comprehensions in Python are very handy. They can also be a little hard to understand when and why you would use them. List comprehensions tend to be harder to read than just using a simple for loop as well. You may want to review the looping chapter before you continue.
If you are ready, then we’ll spend some time looking at how to construct list comprehensions and learn how they can be used. A list comprehension is basically a one line for loop that produces a Python list data structure. Here’s a simple example:
Get hands-on with 1400+ tech skills courses.