0

I have the following list:

lista = [1,2,3,5,0,5,6,0]

I know that print(lista.index(0)) will print the first index where it found the number i.e. 4

How do I get it to print the next index which should be 7 etc?

Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175
Alwina
  • 1

1 Answers1

3

The classic way is to build a list of the indices:

eg:

>>> indices = [i for i, v in enumerate(a) if v == 0]
>>> print indices
[4, 7]

Of course - this can be turned into a generator expression instead. But in short - using enumerate is what you're after.

Jon Clements
  • 138,671
  • 33
  • 247
  • 280