MCPcopy Index your code
hub / github.com/python/cpython / median_low

Function median_low

Lib/statistics.py:351–373  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

349
350
351def 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
376def median_high(data):

Callers

nothing calls this directly

Calls 1

StatisticsErrorClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…