Question #6691
Submitted by Answiki
on 09/21/2022 at 10:56:44 AM UTC
In Python, how to find the index of an element in a list?
Merged questions
Answer
Submitted by Answiki
on 09/21/2022 at 10:58:14 AM UTC
In Python, the .index() method returns the index permet de retourner l'index of the first occurrence of a given element in a list. For example:
>>> myList =['zero', 'one', 'two', 'three', 'four', 'five']
>>> print (myList.index('three'))
3
In this example, it is the first occurrence that is returned:
>>> myList=["a","a","a","b","c","c"]
>>> myList.index('c')
4
Answer by Answiki on 09/21/2022 at 10:58:14 AM
In Python, the .index() method returns the index permet de retourner l'index of the first occurrence of a given element in a list. For example:
>>> myList =['zero', 'one', 'two', 'three', 'four', 'five']
>>> print (myList.index('three'))
3
In this example, it is the first occurrence that is returned:
>>> myList=["a","a","a","b","c","c"]
>>> myList.index('c')
4
Question by Answiki 09/21/2022 at 10:56:44 AM
In Python, how to find the index of an element in a list?
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 13015 | en | https://en.ans.wiki/6691/in-python-how-to-find-the-index-of-an-element-in-a-list | 6 |
Icons proudly provided by Friconix.