Skip to content

Commit

Permalink
Update abs_Max.py (TheAlgorithms#997)
Browse files Browse the repository at this point in the history
* Update abs_Max.py

fix docstring for doctest to work properly (add space after >>>)

* Update abs_Max.py
  • Loading branch information
SandersLin authored and cclauss committed Jul 11, 2019
1 parent 37fbd8c commit b79a197
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions maths/abs_Max.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
def absMax(x):
from typing import List

def abs_max(x: List[int]) -> int:
"""
#>>>absMax([0,5,1,11])
>>> abs_max([0,5,1,11])
11
>>absMax([3,-10,-2])
>>> abs_max([3,-10,-2])
-10
"""
j =x[0]
Expand All @@ -11,15 +13,20 @@ def absMax(x):
j = i
return j

def abs_max_sort(x):
"""
>>> abs_max_sort([0,5,1,11])
11
>>> abs_max_sort([3,-10,-2])
-10
"""
return sorted(x,key=abs)[-1]

def main():
a = [1,2,-11]
print(absMax(a)) # = -11

assert abs_max(a) == -11
assert abs_max_sort(a) == -11

if __name__ == '__main__':
main()

"""
print abs Max
"""

0 comments on commit b79a197

Please sign in to comment.