17

I can get the first index by doing:

l = [1,2,3,1,1]
l.index(1) = 0

How would I get a list of all the indexes?

l.indexes(1) = [0,3,4]

?

David542
  • 101,766
  • 154
  • 423
  • 727

1 Answers1

52
>>> l = [1,2,3,1,1]
>>> [index for index, value in enumerate(l) if value == 1]
[0, 3, 4]
Cory Kramer
  • 107,498
  • 14
  • 145
  • 201