Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)])
 
Comment

PREVIOUS NEXT
Code Example
Python :: image in tkinter 
Python :: pd max rows set option 
Python :: subtract one list from another python 
Python :: make column nullable django 
Python :: foreign key constraint failed django 
Python :: open csv file in python 
Python :: read tsv file column 
Python :: pyqt latex 
Python :: decode base64 with python 
Python :: read data from yaml file in python 
Python :: take first n row of dictionary python 
Python :: drop na in pandas 
Python :: python sort list in reverse 
Python :: trump 
Python :: django print settings 
Python :: read binary file python 
Python :: pandas unnamed zero 
Python :: values of unique from dataframe with count 
Python :: Geopandas to SHP file 
Python :: python read music stream 
Python :: how to create your own programming language in python 
Python :: pandas search for nan in column 
Python :: extract link from text python 
Python :: get first element list of tuples python 
Python :: how to know where python is installed on windows 
Python :: how to run python code on github 
Python :: python clock 
Python :: pandas groupby histogram 
Python :: pandas join two series on index 
Python :: connecting google colab to local runtime 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =