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

15 lines
293 B
Python

# gen.map.filter.py
# finds the cubes of all multiples of 3 or 5 below N
N = 20
cubes1 = map(
lambda n: (n, n**3),
filter(lambda n: n % 3 == 0 or n % 5 == 0, range(N))
)
cubes2 = (
(n, n**3) for n in range(N) if n % 3 == 0 or n % 5 == 0)
print(list(cubes1))
print(list(cubes2))