This is the implementation of the median. :param nums: The list of numeric nums :return: Median of the list >>> find_median(nums=([1, 2, 2, 3, 4])) 2 >>> find_median(nums=([1, 2, 2, 3, 4, 4])) 2.5 >>> find_median(nums=([-1, 2, 0, 3, 4, -4])) 1.5 >>> find_medi
(nums: list[int | float])
| 12 | |
| 13 | |
| 14 | def find_median(nums: list[int | float]) -> float: |
| 15 | """ |
| 16 | This is the implementation of the median. |
| 17 | :param nums: The list of numeric nums |
| 18 | :return: Median of the list |
| 19 | >>> find_median(nums=([1, 2, 2, 3, 4])) |
| 20 | 2 |
| 21 | >>> find_median(nums=([1, 2, 2, 3, 4, 4])) |
| 22 | 2.5 |
| 23 | >>> find_median(nums=([-1, 2, 0, 3, 4, -4])) |
| 24 | 1.5 |
| 25 | >>> find_median(nums=([1.1, 2.2, 2, 3.3, 4.4, 4])) |
| 26 | 2.65 |
| 27 | """ |
| 28 | div, mod = divmod(len(nums), 2) |
| 29 | if mod: |
| 30 | return nums[div] |
| 31 | return (nums[div] + nums[(div) - 1]) / 2 |
| 32 | |
| 33 | |
| 34 | def interquartile_range(nums: list[int | float]) -> float: |
no outgoing calls
no test coverage detected