joelgrus / data-science-from-scratch

code for Data Science From Scratch book
MIT License
8.63k stars 4.5k forks source link

Chapter 5. Statistics, median function #123

Open Zahed-Golabi opened 1 year ago

Zahed-Golabi commented 1 year ago

the median function raise "IndexError" while pass an empty list as an argument to function.

place this lines correct the issue:

elif n == 0: return "The list is empty"

else:
    # if even, return the average of the middle values
    lo = midpoint - 1
    hi = midpoint
    return (sorted_v[lo] + sorted_v[hi]) / 2

Capture