MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / abs_max_sort

Function abs_max_sort

maths/abs.py:58–71  ·  view source on GitHub ↗

>>> abs_max_sort([0,5,1,11]) 11 >>> abs_max_sort([3,-10,-2]) -10 >>> abs_max_sort([]) Traceback (most recent call last): ... ValueError: abs_max_sort() arg is an empty sequence

(x: list[int])

Source from the content-addressed store, hash-verified

56
57
58def abs_max_sort(x: list[int]) -> int:
59 """
60 >>> abs_max_sort([0,5,1,11])
61 11
62 >>> abs_max_sort([3,-10,-2])
63 -10
64 >>> abs_max_sort([])
65 Traceback (most recent call last):
66 ...
67 ValueError: abs_max_sort() arg is an empty sequence
68 """
69 if len(x) == 0:
70 raise ValueError("abs_max_sort() arg is an empty sequence")
71 return sorted(x, key=abs)[-1]
72
73
74def test_abs_val():

Callers 1

test_abs_valFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_abs_valFunction · 0.68