Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Documented solution in Clear category for Median by tomires
def checkio(data):
data.sort() # we need to sort the data first
if len(data) % 2 == 1: a = data[int(len(data)/2)] # if it has an odd length, get the middle number
else: i = int(len(data)/2); a = (data[i] + data[i-1]) / 2 # else get an average out of two numbers in the middle
return a # done
#These "asserts" using only for self-checking and not necessary for auto-testing
April 29, 2014