Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Median by jollyca
def checkio(data):
# obtain a sorted list
new_data = sorted(data)
if (len(new_data) % 2 != 0):
# best case scenario: the length is odd so we just pick the number in the middle
return new_data[len(new_data)//2]
else:
# worst case - the length is even
# so we pick the two middle termsn
terms =[ new_data[len(new_data)//2-1], new_data[len(new_data)//2]]
# and return the average
return sum(terms) / float(len(terms))
#These "asserts" using only for self-checking and not necessary for auto-testing
April 23, 2014
Comments: