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)])
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)])
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us