Files
Learn-Python-Programming-Th…/ch05/even.squares.py
T
adii1823 ef37ce0c4e ch05
2021-10-28 17:38:16 +05:30

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