All problems
Median
Problem
Return the median of data. For odd n it is the middle value of the sorted data; for even n it is the average of the two middle values. Return 0.0 for an empty list.
Hint
Sort first, then branch on the parity of the length.
Test cases
case 1
in: [[1,3,2]]
expected: 2
case 2
in: [[1,2,3,4]]
expected: 2.5
case 3
in: [[5]]
expected: 5
case 4
in: [[7,1,3,3]]
expected: 3
case 5
in: [[]]
expected: 0
Starter codePython
def median(data):
# Your code here
pass5 test cases · run your code against them in the editor