find the closest value in an array python to zero code example
Example: 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)])