Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

strange result when finding the index of a boolean list

John Palmieri suggest to use v.startswith('$a_') in answer to my former question How to construct a condition on the family name of a variable without notice to its index.

Here is a little program

RR=['$x_{0}$',
 '$x_{1}$',
 '$x_{2}$',
 '$a_{3}$',
 '$\\varepsilon_{4}$',
 '$a_{5}$',
 '$\\varepsilon_{6}$']
OB=[v.startswith('$a_') for v in RR]
SS=[OB.index(v) for v in OB if v==True]
SS

which give the answer [3,3] when in my eyes the answer should be [3,5]. is this a bad use of commands on my part ?

strange result when finding the index of a boolean list

John Palmieri suggest to use v.startswith('$a_') in answer to my former question How to construct a condition on the family name of a variable without notice to its index.

Here is a little program

RR=['$x_{0}$',
 '$x_{1}$',
 '$x_{2}$',
 '$a_{3}$',
 '$\\varepsilon_{4}$',
 '$a_{5}$',
 '$\\varepsilon_{6}$']
OB=[v.startswith('$a_') for v in RR]
SS=[OB.index(v) for v in OB if v==True]
SS

which give the answer [3,3] when in my eyes the answer should be [3,5]. I know this is this the standard process to gives the first occurence of the string. But why there is not a bad use of commands on my part defined function which gives all the indexes ?