mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Update abs_Max.py (#997)
* Update abs_Max.py fix docstring for doctest to work properly (add space after >>>) * Update abs_Max.py
This commit is contained in:
parent
37fbd8ca2e
commit
b79a197e8c
|
@ -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]
|
||||
|
@ -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
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user