Question: Exercise 5 Expanding on exercise 4 , create a function to get the k largest elements instead of the k smallest. The rest should be

 Exercise 5 Expanding on exercise 4 , create a function to

Exercise 5 Expanding on exercise 4 , 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]

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 Databases Questions!