11 lines
272 B
Python
11 lines
272 B
Python
# even.squares.py
|
|
# using map and filter
|
|
sq1 = list(
|
|
map(lambda n: n ** 2, filter(lambda n: not n % 2, range(10)))
|
|
)
|
|
|
|
# equivalent, but using list comprehensions
|
|
sq2 = [n ** 2 for n in range(10) if not n % 2]
|
|
|
|
print(sq1, sq1 == sq2) # prints: [0, 4, 16, 36, 64] True
|