Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Median by yurimelnyk
from typing import List, Union
def checkio(data: List[int]) -> Union[int, float]:
"""Calculates median for given list."""
data.sort()
mid_idx = len(data) // 2
if len(data) % 2 == 0:
# for even number of elements we return average of two middle elements
return (data[mid_idx-1] + data[mid_idx]) / 2
else:
return data[mid_idx]
Dec. 27, 2019
Comments: