Python - Index of min or max element - 30 seconds of code Skip to content

Home

Index of min or max element

To find the index of the element with the minimum or maximum value in a list, you can use the min() and max() functions to get the minimum or maximum value in the list, and then use the list.index() method to find the index of that value.

def min_element_index(arr):
  return arr.index(min(arr))

def max_element_index(arr):
  return arr.index(max(arr))

min_element_index([3, 5, 2, 6, 10, 7, 9]) # 2
max_element_index([3, 5, 2, 6, 10, 7, 9]) # 4

More like this

  • Collection · 8 articles

    Python Math

    Learn how to perform common mathematical operations in Python 3.6 with this article collection.

  • Python ·

    Prime factors of number

    Find the list of prime factors of a number, using a simple Python function.

  • Python ·

    Hamming distance

    Learn how to calculate the Hamming distance between two values.

Start typing a keyphrase to see matching articles.