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

Function abs_min

maths/abs.py:18–35  ·  view source on GitHub ↗

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

(x: list[int])

Source from the content-addressed store, hash-verified

16
17
18def abs_min(x: list[int]) -> int:
19 """
20 >>> abs_min([0,5,1,11])
21 0
22 >>> abs_min([3,-10,-2])
23 -2
24 >>> abs_min([])
25 Traceback (most recent call last):
26 ...
27 ValueError: abs_min() arg is an empty sequence
28 """
29 if len(x) == 0:
30 raise ValueError("abs_min() arg is an empty sequence")
31 j = x[0]
32 for i in x:
33 if abs_val(i) < abs_val(j):
34 j = i
35 return j
36
37
38def abs_max(x: list[int]) -> int:

Callers 1

test_abs_valFunction · 0.85

Calls 1

abs_valFunction · 0.85

Tested by 1

test_abs_valFunction · 0.68