Python — Finding the index of an item in a list
If you are working as Python developer, data analysts or data scientists for any organisation then it is very important for you to know how to play with Lists and get the requested info such as matching indexes or items from them.
In Python, Lists store an ordered collection of items which can be of different types. Each item in a list has an assigned index value. It is important to note that Python is a zero indexed based language. All this means is that the first item in the list is at index 0.
If you want to get all the occurrences and the position of one or more items in a list by using Python then there are many ways but you need a very sufficient way to get the matching items from the list.
Let’s see the below example —
MyList = ['Mango', 'Orange', 'Banana', 'Apple', 'Grapes', 'Apple']
Now, you can see here, we have created a list of fruits and want to get the occurrence of Apple from the list and Python program will store this list as given below -
In the above list, you can see that Python based list is starting with 0 index and end with total item-1. In our cases, last index value in our fruit list will be 6–1 =5
Now, this point is How to get the occurrence of a item in the list. You could use a list…