Editor settings

General settings

Save settings

Learn to program with Python

Find index of element in list #

Write a function that finds the index of a given element in a list. If the value is not found in the given list, return the value None.


Tests #

  • get_index([1, 2, 3], 1) should return 0
  • get_index([1, 2, 3], 0) should return None
  • get_index(["A", "B", "C"], "A") should return 0
  • get_index(["A", "B", "C"], "C") should return 2
  • get_index(["A", "B", "C"], "a") should return None
  • get_index(["A", "B", "C"], 0) should return None

Hints #

  • Use the function enumerate to get both the index and the value to loop through the given list.
Output will be displayed here