diff --git a/maths/abs_max.py b/maths/abs_max.py index 4a4b4d9ebca3..9646d550ec07 100644 --- a/maths/abs_max.py +++ b/maths/abs_max.py @@ -14,11 +14,7 @@ def abs_max(x: list[int]) -> int: """ if len(x) == 0: raise ValueError("abs_max() arg is an empty sequence") - j = x[0] - for i in x: - if abs(i) > abs(j): - j = i - return j + return max(x, key=abs) def abs_max_sort(x: list[int]) -> int: