For a non-empty list, use values.index(max(values)) to get the zero-based index of the first occurrence of the largest value. If you need every index tied for the maximum, compare each value with max(values) while enumerating the list.
Find the first index of the maximum value
Call max() to get the largest item, then call the list’s index() method to find its first position:
As an Amazon Associate I earn from qualifying purchases.
values = [4, 9, 2, 9, 6]
max_index = values.index(max(values))
print(max_index) # 1
The largest value is 9, which appears at indices 1 and 3. Python list indices start at zero, and list.index() returns the first occurrence of the requested value. See the Python tutorial’s list-method documentation.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Return every index tied for the maximum
index() returns just one position. To collect every position where the maximum occurs, find the maximum once and filter the indexed values:
#1 Best Overall
values = [4, 9, 2, 9, 6]
maximum = max(values)
max_indices = [i for i, value in enumerate(values) if value == maximum]
print(max_indices) # [1, 3]
enumerate() pairs each value with its index, and the comparison keeps each position whose value equals the maximum.
Use one pass when working with an iterable
If you want both the winning index and its value, or your input is a general iterable rather than a list, take the maximum of the indexed pairs:
Rank #2
index, value = max(enumerate(values), key=lambda pair: pair[1])
The key function tells max() to compare each pair by its value. This scans the iterable once. For a list and a beginner-friendly expression, values.index(max(values)) is often easier to follow.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Handle an empty list
An empty list has no maximum: max([]) raises ValueError. Check for an item before calling max(), and decide how your program should represent the empty case:
if values:
max_index = values.index(max(values))
else:
max_index = None
You can also pass a default to max() for an empty iterable, but that default is not a real list index. Do not pass it to index() as though it identified an actual maximum.
Choose an approach based on the result you need
- First maximum index: use
values.index(max(values)). - All maximum indices: compute the maximum, then enumerate and filter the list.
- Index and value from an iterable: use
max(enumerate(values), key=lambda pair: pair[1]), with a separate empty-input strategy if needed.
For built-in lists, the two-step approach performs two linear scans—one for max() and one for index()—so its total time complexity is still O(n). A single-pass maximum can be useful when the iterable cannot be restarted or when you need the value as well as its position. CPython’s complexity reference lists max(l) as O(n) and sorting as O(n log n); those figures describe CPython and built-in types, so other implementations or custom classes may differ. Sorting just to locate the maximum is usually unnecessary, and list.sort() changes the list in place.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.




