Files
company-haness/benchmark/fixtures/GT-R2/stats.py
T

17 lines
422 B
Python

"""Running statistics — contains a bug in `median` for even-length inputs.
The bug: for an even number of elements, `median` returns the lower-middle element
instead of the average of the two middle elements. `mean` is correct.
"""
def mean(xs):
return sum(xs) / len(xs)
def median(xs):
s = sorted(xs)
n = len(s)
mid = n // 2
return s[mid] # BUG: even-length should average s[mid-1] and s[mid]