Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Math.median solution in Clear category for Median of Three by Striga
from typing import Iterable
from statistics import median
def median_three(els: Iterable[int]) -> Iterable[int]:
return els[:2] + [median(els[i:i+3]) for i in range(len(els)-2)]
if __name__ == '__main__':
assert list(median_three([1, 2, 3, 4, 5, 6, 7])) == [1, 2, 2, 3, 4, 5, 6]
assert list(median_three([1])) == [1]
Nov. 24, 2020
Comments: