Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started