Why it is wrong


#1
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


#2

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


#3

yep, great thanks, i undesrtood