0
0
PythonHow-ToBeginner · 3 min read

How to Find Index of Minimum Value in List in Python

Use the min() function to find the smallest value in the list, then use list.index() to get its index. For example, index = my_list.index(min(my_list)) finds the index of the minimum value.
📐

Syntax

To find the index of the minimum value in a list, combine the min() function and the list.index() method.

  • min(list): Returns the smallest value in the list.
  • list.index(value): Returns the index of the first occurrence of value in the list.

Putting them together: list.index(min(list)) gives the index of the smallest value.

python
index = my_list.index(min(my_list))
💻

Example

This example shows how to find the index of the minimum value in a list of numbers.

python
my_list = [5, 3, 9, 1, 7]
min_value = min(my_list)
min_index = my_list.index(min_value)
print(f"Minimum value: {min_value}")
print(f"Index of minimum value: {min_index}")
Output
Minimum value: 1 Index of minimum value: 3
⚠️

Common Pitfalls

One common mistake is assuming the minimum value is unique. If the minimum value appears multiple times, list.index() returns the first occurrence only.

Also, calling min() or index() on an empty list will cause an error.

python
my_list = [2, 1, 3, 1, 4]
# This returns the index of the first minimum value (1), which is 1
min_index = my_list.index(min(my_list))
print(min_index)  # Output: 1

# Correct approach if you want all indices:
min_val = min(my_list)
all_min_indices = [i for i, v in enumerate(my_list) if v == min_val]
print(all_min_indices)  # Output: [1, 3]
Output
1 [1, 3]
📊

Quick Reference

Summary tips for finding the index of the minimum value in a list:

  • Use min(list) to get the smallest value.
  • Use list.index(value) to find the first index of that value.
  • For multiple minimum values, use a list comprehension with enumerate().
  • Check if the list is empty before calling these functions to avoid errors.

Key Takeaways

Use min() to find the smallest value in the list.
Use list.index() with min() to get the index of the minimum value.
If the minimum value appears multiple times, list.index() returns the first occurrence.
Use enumerate() with a list comprehension to find all indices of the minimum value.
Avoid calling min() or index() on empty lists to prevent errors.