How to Find the Index of the Minimum Element in a List in Python

  • Home /
  • Blog Posts /
  • How to Find the Index of the Minimum Element in a List in Python

If you need to find the index of the minimum element in a list, you can do one of the following:

Option 1 – Using min() and index()

lst = [8,6,9,-1,2,0]
m = min(lst)
print(lst.index(m))

Output: 3

Option 2 – Using min() and for

lst = [8,6,9,-1,2,0]
m = min(lst)
for i in range(len(lst)):
    if(lst[i]==m):
        print(i)
        break

Output: 3

Option 3 – Using min() and enumerate()

lst = [8,6,9,-1,2,0]
a,i = min((a,i) for (i,a) in enumerate(lst))
print(i)

Output: 3

Option 4 – Using min() and operator.itemgetter()

from operator import itemgetter
lst = [8,6,9,-1,2,0]
i = min(enumerate(lst), key=itemgetter(1))[0]
print(i)

Output: 3

Option 5 – Using numpy.argmin()

import numpy as np
lst = [8,6,9,-1,2,0]
i = np.argmin(lst)
print(i)

Output: 3