Wednesday, March 8, 2023
HomeSoftware EngineeringMethods to Discover the Index of the Minimal Factor in a Listing...

# Methods to Discover the Index of the Minimal Factor in a Listing in Python

If that you must discover the `index` of the minimal ingredient in a listing, you are able to do one of many following:

## Choice 1 – Utilizing `min()` and `index()`#

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

Output: `3`

## Choice 2 – Utilizing `min()` and `for`#

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

Output: `3`

## Choice 3 – Utilizing `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`

## Choice 4 – Utilizing `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`

## Choice 5 – Utilizing `numpy.argmin()`#

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

Output: `3`

RELATED ARTICLES