Median


#1


Oops, try again. median([4, 5, 5, 4]) returned 5.0 instead of 4.5


def median(l):
    l.sort()
    if len(l)%2==0:
        med=l[len(l)/2] + l[len(l)/2+1]
        med=float(med/2)
    else:
        mid=len(l)/2
        med=l[mid]
    return med


#2

[4, 5, 5, 4] has 4 items, which means the indexes are: 0, 1, 2, 3

which are the two middle indexes and which indexes are you using?


#3

Got it! :slight_smile: thank you.


#4