2022-12-05 17:53:38 +00:00
|
|
|
def main():
|
2023-01-30 16:48:43 +00:00
|
|
|
lst = [1, 2, 4, 5, 6]
|
2022-12-05 17:53:38 +00:00
|
|
|
print(median(lst))
|
|
|
|
|
|
|
|
|
|
|
|
def median(lst):
|
|
|
|
lst = sorted(lst, reverse=True)
|
|
|
|
if len(lst) % 2 == 0:
|
2023-01-30 16:48:43 +00:00
|
|
|
middle = len(lst) // 2 - 1
|
2023-05-16 20:00:37 +00:00
|
|
|
return sum(lst[middle:middle + 2]) / 2
|
2022-12-05 17:53:38 +00:00
|
|
|
else:
|
|
|
|
return lst[len(lst) // 2]
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|