0
Explain map & filter
2 Answers
+ 4
x = [x for x in range(1,10)]
# original array
print(x)
# array with each element squared
print(tuple(map(lambda y:y**2,x)))
# filter out he odd elements
print(tuple(filter(lambda y:y%2==0,x)))
both functions work on an array of elements with the difference being that map will apply a function on each element
and filter will filter out the elements which does not meet the given criteria (in this case, not even numbers)
refer to the code above as an example (can run it in this app)
0
thank u