Return the low median of numeric data. When the number of data points is odd, the middle value is returned. When it is even, the smaller of the two middle values is returned. >>> median_low([1, 3, 5]) 3 >>> median_low([1, 3, 5, 7]) 3
(data)
| 349 | |
| 350 | |
| 351 | def median_low(data): |
| 352 | """Return the low median of numeric data. |
| 353 | |
| 354 | When the number of data points is odd, the middle value is returned. |
| 355 | When it is even, the smaller of the two middle values is returned. |
| 356 | |
| 357 | >>> median_low([1, 3, 5]) |
| 358 | 3 |
| 359 | >>> median_low([1, 3, 5, 7]) |
| 360 | 3 |
| 361 | |
| 362 | """ |
| 363 | # Potentially the sorting step could be replaced with a quickselect. |
| 364 | # However, it would require an excellent implementation to beat our |
| 365 | # highly optimized builtin sort. |
| 366 | data = sorted(data) |
| 367 | n = len(data) |
| 368 | if n == 0: |
| 369 | raise StatisticsError("no median for empty data") |
| 370 | if n % 2 == 1: |
| 371 | return data[n // 2] |
| 372 | else: |
| 373 | return data[n // 2 - 1] |
| 374 | |
| 375 | |
| 376 | def median_high(data): |
nothing calls this directly
no test coverage detected
searching dependent graphs…