Makistos
6/16/2016 - 6:42 AM

Calculating the median from a list in Python. #python

Calculating the median from a list in Python. #python

def median(l):
    sortedl = sorted(l)

    mid = (len(sortedl) -1) // 2

    if (len(sortedl)) % 2:
        return (sortedl[mid] + sortedl[mid+1]) / 2.0
    else:
        return sortedl[mid]