Middle value
Write code · Basic · §6.1 Putting things in order
Complete the function solution, which returns the value in the middle when the integer list nums is sorted in ascending order.
If there is an even number of elements, return the smaller of the two middle values. Do not change the original list nums.
Function
solution(nums)
Constraints
- The length of
numsis from 1 to 1,000. - Each element of
numsis an integer from -1,000,000 to 1,000,000.
Examples
| nums | result |
|---|---|
[5, 1, 4] | 4 |
[8, 2, 6, 4] | 4 |
Starter code
def solution(nums):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.