Oops, try again.
median([4, 5, 5, 4]) returned 3.5 instead of 4.5
In theory my code is expected to work correctly, but instead it always returns a bad value rather then expected one. Where is the error?
def median(x): if len(x) % 2 != 0: m = len(x) / 2 return x[m - 1] elif len(x) % 2 == 0: xl = sorted(x) l = len(x) / 2 v = l + 1 c = xl[l] + xl[v] / 2.0 return c