Python: Find index of minimum item in list of floats [duplicate] Python: Find index of minimum item in list of floats [duplicate] python python

Python: Find index of minimum item in list of floats [duplicate]


I would use:

val, idx = min((val, idx) for (idx, val) in enumerate(my_list))

Then val will be the minimum value and idx will be its index.


You're effectively scanning the list once to find the min value, then scanning it again to find the index, you can do both in one go:

from operator import itemgettermin(enumerate(a), key=itemgetter(1))[0] 


Use of the argmin method for numpy arrays.

import numpy as npnp.argmin(myList)

However, it is not the fastest method: it is 3 times slower than OP's answer on my computer. It may be the most concise one though.