My Coding > Programming language > Python > Python FAQ > Python: How to find the index of the max value in a list

Python: How to find the index of the max value in a list

Question: How to find the index of the max value in a list in Python

This is common question for many tasks. To solve it we need to use function for max search max() and a list method index()

The procedure is very simple:

  • Find the max value in the Python list
  • Identify index of max value
  • Return or publish results

The same algorithm can be used to find the index of min valuer in a list


L = [1, 4, 5, 16, 3, 45, 3] # we need to find index of max value in the list
M = max(L)                  # 45 - Search max value with external function
I = L.index(M)              # 5 - search for fist entrance of max value
print("L[{}] = {} - is the maximal".format(I,M))
                            # L[5] = 45 - is the maximal


Published: 2021-10-07 04:13:32

Last 10 artitles


9 popular artitles

© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.