Given a list and we have to find the index of first matched of a list in Python.
Example:
Input:
List = [10, 20, 10, 20, 30, 40, 50]
element = 10
Output:
Index of first matched 10 is: 0
Input:
List = [10, 20, 10, 20, 30, 40, 50]
element = 30
Output:
Index of first matched 20 is: 4
list.index() Method
It’s an inbuilt method in Python, it returns the index of first matched element of a list.
Syntax:
list.index(element)
Here, list is the name of the list and element is the element/item whose first matched index to be returned.
Program to find the index of first matched element in Python
Output
0 1 4 5 6need an explanation for this answer? contact us directly to get an explanation for this answer