.index() show index of both similar elements from a list

Mike Yung

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)?

RoadRunner

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]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Set vs List when need both unique elements and access by index

Remove all elements from a List after a particular index

Remove multiple elements from a list of index with Python

Naming elements of a nested list from their index in R

Getting the index of similar consecutive elements in list (Python3)

How to print every third element from current index in list of elements

Removing elements from a list by index from another list of integers

Return a list from a list of lists with elements picked by index

Add a range of elements to a list at a given index, replacing the its contents from that index in the list and resizing it (if need it)

Delete elements from python array with given index of elements as list

Pick random integers from list elements of same index and generate a list

Extract same index elements from a list

Retrieve array elements from a list of index

How to compare the index of 2 sublists' elements from a list of lists

How to delete elements from a List synchronously by Index?

container with both unique elements and access by index

Swapping elements based on index given from another list

I want to print the pair of elements of a list starting from 1 index

How to combine elements from the list taking into account index of the list?

List Index Out Of Bounds when deleting elements from TObjectList

Show index of each string in a list

How to make a function to remove elements by index from a list

index of N highest elements from a list of numpy array

Prolog remove elements which have the same value as the index from the list

Remove elements from a List at a specific index

Remove duplicates from a list and remove elements at same index in another list

Get elements from list in python by ¿index?

Appending elements with similar index in Python

List in python does not show index