Python | Find Index of Minimum Number in List

Python’s List Object type is quite useful for storing data while dealing with Scientific Computations where large amount of data need to be processed. Anyway, in this article => I’ll discuss How to find index of Minimum Element in a Python List?

Now there can be two possible scenarios in which List have just Minimum Number once and other can be situation where list have same minimum numbers twice. [10, 2, 2, 2, 13] this list have Minimum Number = 2 three times, so for this list Python Program should return three index values 1, 2, 3. Similarly [19, 2, 1, 10] list have Minimum Number = 1 just once, so for this list Python Program should return 2. Quite Simple, Just need to write a Python Program which takes care of multiple occurrences of Minimum Number in List. Let’s get into Python Code now for Finding Minimum Number’s Index in a List.

# Python Program to Find smallest number indexes in List

a_list = [19, 2, 2, 10, 29, 2, 2, 3]     # Define List

smallest_number = min(a_list)					   # Smallest Number in Python List

indexes_of_smallest_number = []

for i in range(len(a_list)):
	if a_list[i] == smallest_number:
		indexes_of_smallest_number.append(i)

print("Indexes of Minimum Number in Python List are => ", indexes_of_smallest_number)

Output of Above Code

Indexes of Minimum Number in Python List are =>  [1, 2, 5, 6]

Gagan

Hi, there I'm founder of ComputerScienceHub(Started this to bring useful Computer Science information just at one place). Personally I've been doing JavaScript, Python development since 2015(Been long) - Worked upon couple of Web Development Projects, Did some Data Science stuff using Python. Nowadays primarily I work as Freelance JavaScript Developer(Web Developer) and on side-by-side managing team of Computer Science specialists at ComputerScienceHub.io

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts