Why it is wrong

def median(lst):
    for i in range(len(lst)):
        if len(lst)%2==0:
            return (lst[int(len(lst)/2)-1]+lst[int(len(lst)/2)])/2.0
        elif len(lst)==1:
            return lst[i]
        elif  len(lst)%2!=0:
            return lst[int(len(lst)/2)]

i really do not understand why i'm wrong
It is an error:
Oops, try again. median([4, 5, 5, 4]) returned 5.0 instead of 4.5

But median for this case is (5+5)/2=5


you need to compute the median of a sorted list otherwise it isn't really useful as a mean, is it?


yep, great thanks, i undesrtood