From e79b13b5d2c7ad2d6587056797be4cf21539ee79 Mon Sep 17 00:00:00 2001 From: Lukas Esc <55601315+Luk-ESC@users.noreply.github.com> Date: Fri, 14 Oct 2022 21:09:33 +0200 Subject: [PATCH] shorten code using max function replaced the for loop with a call to max() using the key argument --- maths/abs_max.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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: