Python/maths/abs_min.py
Sanders Lin c2f2fa8b23 Update abs_Min.py (#1004)
* Update abs_Min.py

* Create __init__.py

* Rename abs_Min.py to abs_min.py

* Update abs_min.py
2019-07-11 18:20:41 +02:00

21 lines
322 B
Python

from abs import abs_val
def absMin(x):
"""
# >>>absMin([0,5,1,11])
0
# >>absMin([3,-10,-2])
-2
"""
j = x[0]
for i in x:
if abs_val(i) < abs_val(j):
j = i
return j
def main():
a = [-3,-1,2,-11]
print(absMin(a)) # = -1
if __name__ == '__main__':
main()