In this lesson, you saw how to write a simple list comprehension that computes the squares of numbers from 0 to 9 and assigns the result to the squares
variable.
You also learned that list comprehensions look similar to list constants and that they can be transformed into for loops. The code examples below illustrate this:
List comprehension
>>> squares = [x * x for x in range(10)]
>>>
>>> squares
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
For Loop
>>> squares = []
>>> for x in range(10):
... squares.append(x * x)
...
...
>>> squares
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
kkruch on March 14, 2019
It would be great if you have an autoplay feature for videos.