Answers for "how to find the closest value to zero from an array with positive and negative numbers in python"

0

python find closest value in list to zero

# ------- FIND VALUE (AND INDEX) CLOSEST TO ZERO INSIDE A LIST ------- # 

myList = [23, -2, 20, 19, -10, 4]
min_val, idx = min([(abs(val), idx) for (idx, val) in enumerate(myList)])
Posted by: Guest on August-30-2020

Code answers related to "how to find the closest value to zero from an array with positive and negative numbers in python"

Python Answers by Framework

Browse Popular Code Answers by Language