So I already got my code to work (and having now compared it to some others I see that mine is ridiculously bloated). I was just wondering if anyone can explain why sorted works in this case, but trying new = x.sort() does not work. Since what is provided is a list, shouldn't the sort function work? The error I would receive with x.sort() was:
Oops, try again.
median() resulted in an error: object of type 'NoneType' has no len()
I apologize in advanced if this is a stupid question.
def median(x): new = sorted(x) if len(new) % 2 == 0: c = len(new) / 2 e = len(new) / 2 - 1 d = (new[c] + new[e]) / 2.0 else: c = len(new) / 2.0 e = int(c) d = new[e] return d