Question: create a function to get the k largest elements instead of the k smallest. The rest should be the same. Don't forget to add
create a function to get the k largest elements instead of the k smallest. The rest should be the same. Don't forget to add an appropriate docstring. To test your code, use the below main program: test [2,7,9,3,6,5,1,1,2,9] test2 [2,7,3,3] print("First test: ") print("Before function: ", test) print("Five largest: ", kMax(test, 5)) print("After function: ", test) print("Second test: ") print("Before function:",test2) print("Five largest: ", kMax (test2,5)) print("After function:",test2) You should then be able to get the following sample run: First test: Before function: [2, 7, 9, 3, 6, 5, 1, 1, 2, 9] Five largest: [5, 6, 7, 9, 9] After function: [2, 7, 9, 3, 6, 5, 1, 1, 2, 9] Second test: Before function: [2, 7, 3, 3] Five largest: [2, 3, 3, 7] After function: [2, 7, 3, 3] G
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
