Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions