Ask Your Question

Revision history [back]

As you note, that's how index works: it returns the index of the first element that matches. There are ways of finding all occurrences of an element in a list: see for example https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list. That leads to

[i for i, v in enumerate(OB) if v==True]

or slightly more briefly

[i for i, v in enumerate(OB) if v]

or skipping OB

[i for i, v in enumerate(RR) if v.startswith('$a_')]

(enumerate is documented here.)