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

Function abs_max

maths/abs.py:38–55  ·  view source on GitHub ↗

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

(x: list[int])

Source from the content-addressed store, hash-verified

36
37
38def abs_max(x: list[int]) -> int:
39 """
40 >>> abs_max([0,5,1,11])
41 11
42 >>> abs_max([3,-10,-2])
43 -10
44 >>> abs_max([])
45 Traceback (most recent call last):
46 ...
47 ValueError: abs_max() arg is an empty sequence
48 """
49 if len(x) == 0:
50 raise ValueError("abs_max() arg is an empty sequence")
51 j = x[0]
52 for i in x:
53 if abs(i) > abs(j):
54 j = i
55 return j
56
57
58def abs_max_sort(x: list[int]) -> int:

Callers 1

test_abs_valFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_abs_valFunction · 0.68