Let's say I have a list
list = [1,2,1,3,4,5]
How do I find the index of both the 1
from the list using .index()
function in python(or any other methods)?
Just use enumerate()
instead:
>>> lst = [1,2,1,3,4,5]
>>> index_one = [i for i, x in enumerate(lst) if x == 1]
>>> index_one
[0, 2]