Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First Normal solution solution in 3rd party category for Median of Three by kim.yangjin
from numpy import median
def median_three(items):
if len(items) < 3: return items
result = [items[0],items[1]]
for i in range(2,len(items)):
threenumbers = [items[i-2],items[i-1],items[i]]
result.append(int(median(threenumbers)))
return result
if __name__ == '__main__':
print("Example:")
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!")
Feb. 19, 2022