This lesson continued the discussion on filtering, this time using a for
loop to generate a list of squares. The for
loop does exactly what the list comprehension from the last lesson did and the output is the same.
You saw that, using a for
loop, the code turns out this way:
>>> even_squares = []
>>> for x in range(10):
... if x % 2 == 0:
... even_squares.append(x * x)