15. Median


#1

My code is not working. Can anyone help me fix it?

def median(l):
    l.sort()
if len(l)==1:
    return l[0]
if len(l) % 2 != 0:
    return l[len(l)/2]
else:
    return (l[len(l)/2] + l[len(l)/2 - 1]) / 2.0

ERROR:
File "python", line 4
SyntaxError: 'return' outside function
Please help


#2

Correct the indentation so all the code is in the function block. Currently the only line in the block is,

    l.sort()

From a practical point of view, l is not a very readable variable name since it looks so much like a 1. Recommend use a name of at least a letter that does not look like a number.