20

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
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

58
>>> l = [1,2,3,1,1]
>>> [index for index, value in enumerate(l) if value == 1]
[0, 3, 4]
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218