ch05
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user