Question: ( Filter / Map Performance ) With regard to the following code: numbers = [ 1 0 , 3 , 7 , 1 , 9

(Filter/Map Performance) With regard to the following code:
numbers =[10,3,7,1,9,4,2,8,5,6]
list(map(lambda x: x **2,
filter(lambda x: x %2!=0, numbers)))
a) How many times does the filter operation call its lambda argument?
b) How many times does the map operation call its lambda argument?
c) If you reverse the filter and map operations, how many times does the map operation call its lambda argument?
To help you answer the preceding questions, define functions that perform the same tasks
as the lambdas. In each function, include a print statement so you can see each time the
function is called. Finally, replace the lambdas in the preceding code with the names of
your functions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!