프로그래밍 문제/[Python] CheckIO
[CheckIO] Median
UltraLowTemp-Physics
2021. 3. 23. 11:34
1. Problem: py.checkio.org/en/mission/median/
2. My solution:
def checkio(data: List[int]) -> [int, float]:
dummy = sorted(data)
len_list = len(dummy)
# For odd elements
if len_list % 2 == 1: return dummy[len_list // 2]
# For even elements
else: return (dummy[len_list // 2 - 1] + dummy[len_list // 2]) / 2