Skip to content

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,] m = min(lst) print(lst.index(m))
Code language: Python (python)

Output: 3

Option 2 – Using min() and for

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

Output: 3

Option 3 – Using min() and enumerate()

lst = [8,6,9,-1,2,] a,i = min((a,i) for (i,a) in enumerate(lst)) print(i)
Code language: Python (python)

Output: 3

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

from operator import itemgetter lst = [8,6,9,-1,2,] i = min(enumerate(lst), key=itemgetter(1))[] print(i)
Code language: Python (python)

Output: 3

Option 5 – Using numpy.argmin()

import numpy as np lst = [8,6,9,-1,2,] i = np.argmin(lst) print(i)
Code language: Python (python)

Output: 3

See also  How to Normalize a List of Numbers in Python
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x