0

How do I get index of all the places where the same element is present. I have been using the index() method, but I only get the index of the first apperance of that element.

print([1, 1, 2, 3].index(1))

I need both an output of both 0 and 1. My knowlegde about coding terms is very bad sorry, thanks in advance.

Hugo B
  • 1

1 Answers1

0
print([i for i, x in enumerate([1, 1, 2, 3]) if x==1])
[0, 1]
Lior Cohen
  • 5,570
  • 2
  • 14
  • 30