Question: BONUS Question: That guy has no filter... (4 points) Filtering a list is similar to filtering water. You keep what you want, and throw the

BONUS Question: That guy has no filter... (4 points) Filtering a list is similar to filtering water. You keep what you want, and throw the rest away. In programming, filter operations are performed over data structures, with a boolean condition controlling whether or not a value gets thrown away. We can generalize filter operations for all possible boolean conditions using functions as arguments! Write a function in python filtr(f, L) which, given function f and a list L , returns a filtered version of the list. A value in the list may be considered to have gotten through" the filter if, when given to the function f , f returns True . If f returns anything other than True, that element should be discarded. In [ ]: def filtr(f, L) : pass # YOUR CODE HERE raise Not ImplementedError() In [ ]: print("Test 1 : print("Test 2 : print("Test 1 : ", filtr(lambda x : x >= 10, list(range (20))) == list (range(10,20))) ", filtr(lambda x: "Bananas", list(range (20) ) ) == 0) ", filtr(lambda x : x 2 == 1, list(range (20))) == list(range(1, 20, 2))) In [ ]: In [ ]: In [ ]: In [ ]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
