Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Median of Three by Sarina
from typing import Iterable
from statistics import median
def median_three(els: Iterable[int]) -> Iterable[int]:
result = els[:2]
if len(els) > 2:
for i in range(3, len(els)+1):
result.append(median(els[i-3:i]))
return result
if __name__ == '__main__':
print("Example:")
#print(list(median_three([1])))
print(list(median_three([1, 2, 3])))
print(list(median_three([1, 2, 3, 4, 5, 6, 7])))
# These "asserts" are used for self-checking and not for an auto-testing
assert list(median_three([1, 2, 3, 4, 5, 6, 7])) == [1, 2, 2, 3, 4, 5, 6]
assert list(median_three([1])) == [1]
print("Coding complete? Click 'Check' to earn cool rewards!")
March 21, 2020