You are viewing a single comment's thread. Return to all comments →
def quartiles(arr): arr.sort() def median(arr): n = len(arr) idx = n // 2 if n % 2 == 0: return round((arr[idx-1] + arr[idx]) / 2) else: return round(arr[idx]) n = len(arr) idx = n // 2 return [ median(arr[:idx]), median(arr), median(arr[idx:] if n % 2 == 0 else arr[idx+1:]), ]
Seems like cookies are disabled on this browser, please enable them to open this website
Day 1: Quartiles
You are viewing a single comment's thread. Return to all comments →