MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / median_of_five

Function median_of_five

searches/median_of_medians.py:12–28  ·  view source on GitHub ↗

Return the median of the input list :param arr: Array to find median of :return: median of arr >>> median_of_five([2, 4, 5, 7, 899]) 5 >>> median_of_five([5, 7, 899, 54, 32]) 32 >>> median_of_five([5, 4, 3, 2]) 4 >>> median_of_five([3, 5, 7, 10, 2]) 5

(arr: list)

Source from the content-addressed store, hash-verified

10
11
12def median_of_five(arr: list) -> int:
13 """
14 Return the median of the input list
15 :param arr: Array to find median of
16 :return: median of arr
17
18 >>> median_of_five([2, 4, 5, 7, 899])
19 5
20 >>> median_of_five([5, 7, 899, 54, 32])
21 32
22 >>> median_of_five([5, 4, 3, 2])
23 4
24 >>> median_of_five([3, 5, 7, 10, 2])
25 5
26 """
27 arr = sorted(arr)
28 return arr[len(arr) // 2]
29
30
31def median_of_medians(arr: list) -> int:

Callers 2

median_of_mediansFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected