📜  python在列表中找到最接近零的值 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:07.345000             🧑  作者: Mango

代码示例1
# ------- 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)])