Skip to content

Python code snippet – How to return max num index?

# any list
a = [1, 7, 3, 12, 5]

# index of minimum element
# if more than 1 minimum, 
# first index is returned
min_index = a.index(min(a))

# index of maximum element
max_index = a.index(max(a))
See also  How to use a class in Python?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.