Answers for "get closest number in list 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 "get closest number in list python"

Python Answers by Framework

Browse Popular Code Answers by Language