15. median


#1


Watch this link https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/5?curriculum_id=4f89dab3d788890003000096#
What is wrong?
ERROR: Oops, try again. median([1]) returned [1] instead of 1

def median(lst):
    lst = sorted([lst])
    if len(lst)%2==0:
        med = (lst[len(lst)/2]+lst[len(lst)/2-1])/2
    else:
        med = lst[(len(lst)-1)/2]
    return med


#2

lets add a function call so we can see what is actually happening:

def median(lst):
    lst = sorted([lst])
    print lst
    if len(lst)%2==0:
        med = (lst[len(lst)/2]+lst[len(lst)/2-1])/2
    else:
        med = lst[(len(lst)-1)/2]
    return med
print median([1])

i also added another print statement, as you can see, because you do: sorted([lst]), you get a nested list. i would just simple do: sort(lst)

That should solve your current problem, please try again to resolve the other issues, if you need more help, post an updated version of your code


#3

Thanks!
I've corrected it.