>>> 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])
| 36 | |
| 37 | |
| 38 | def 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 | |
| 58 | def abs_max_sort(x: list[int]) -> int: |