1. (8 points) a. Given the following program which uses the built-in filter function to select elements of a list n (see
Posted: Tue Jul 12, 2022 8:09 am
1. (8 points) a. Given the following program which uses the built-in filter function to select elements of a list n (see below in the program), complete the program by: (1) define a function myfune which take a list argument and check if the median of the list is greater than 5. Then use the function as a parameter of the filter function to filter all elements of n that have median greater than 5; (2) defining a lambda and use it in filter as the parameter to filter all list elements with mean greater than 10. After that, print the result. import math import statistics n-[[1, 3, 5, 8, 7, 6, 10], [2, 4, 6, 8, 9, 10], [12, 15, 18, 19, 20]] # list of lists def myfunc( a ): median_result filter( mean_result-filter( n) n) #apply median to each element in n #apply lambda to each element in n print( b. Complete the set_operation function in the following program: assume the three parameters a, b, and c are sets of student names (i.e., string type) from three different courses: Algebra, Biology, and CS1, respectively. Using set operation to find: (1) how many students are taking either Algebra or Biology, but not both; (2) how many are taking all three courses; (3) which course has the smallest enrollment? What is the class size difference between the largest one and the smallest one? import math def set_operation(a, b, c): # a, b, c are sets of strings, c.g., a {"Peter", "John"}