Question
In this problem, you are given the list of numbers and the parameter _m_ and you want to return the **_values_** of the _m_ smallest
In this problem, you are given the list of numbers and the parameter _m_ and you want to return the **_values_** of the _m_ smallest numbers.
E.g. If the list is \[7, 4, 1, 3, 6, 8, 2, 5\] and _m_ is 3 then the _m_ smallest values are 1, 2, and 3.
def mSmallest(L, m):
"""
Pre: L is a list of integers, m <= length(L)
Post: A list of the values of the m smallest elements of L has been returned.
"""
# Initialize the result list
ms = [] # At the end of the function, ms will be a list of the m smallest values in L.
... # Replace this whole line with the lines of your function
return ms
Questions
What should be the output of the following function call? -> B = list(range(10))
What should happen if you try it with a value of _m_ greater than the size of the list? Provide the code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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