I have a problem with a pice of my code. I have a boolean list and need to know which index is true.
lst = [True, True, False]
for element in lst:
print(lst.index(element))
why the output is 0,0,2?
I just need output 0,1,2
I have a problem with a pice of my code. I have a boolean list and need to know which index is true.
lst = [True, True, False]
for element in lst:
print(lst.index(element))
why the output is 0,0,2?
I just need output 0,1,2
Do this.
lst = [True, True, False]
for idx, val in enumerate(lst):
if val == True:
print(idx)
The output
0
1
This will print only the true, so I'm not sure if its exactly what you need. If you provide more context we could probably help get a better answer for your specific problem.
lst = [True, True, False]
for element in lst:
if element == True:
print(element)