Skip to content

Commit fa5f11d

Browse files
SandersLinstokhos
authored andcommitted
Update abs_Max.py (TheAlgorithms#997)
* Update abs_Max.py fix docstring for doctest to work properly (add space after >>>) * Update abs_Max.py
1 parent 582441a commit fa5f11d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

maths/abs_Max.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
def absMax(x):
1+
from typing import List
2+
3+
def abs_max(x: List[int]) -> int:
24
"""
3-
#>>>absMax([0,5,1,11])
5+
>>> abs_max([0,5,1,11])
46
11
5-
>>absMax([3,-10,-2])
7+
>>> abs_max([3,-10,-2])
68
-10
79
"""
810
j =x[0]
@@ -11,15 +13,20 @@ def absMax(x):
1113
j = i
1214
return j
1315

16+
def abs_max_sort(x):
17+
"""
18+
>>> abs_max_sort([0,5,1,11])
19+
11
20+
>>> abs_max_sort([3,-10,-2])
21+
-10
22+
"""
23+
return sorted(x,key=abs)[-1]
1424

1525
def main():
1626
a = [1,2,-11]
17-
print(absMax(a)) # = -11
18-
27+
assert abs_max(a) == -11
28+
assert abs_max_sort(a) == -11
1929

2030
if __name__ == '__main__':
2131
main()
2232

23-
"""
24-
print abs Max
25-
"""

0 commit comments

Comments
 (0)