从布尔列表中获取所有索引
我的一段代码有问题。我有一个布尔列表,需要知道哪个索引是真的。
lst = [True, True, False]
for element in lst:
print(lst.index(element))
为什么输出是0,0,2?
我只需要输出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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样做。
输出
Do this.
The output
这只会打印真实的,所以我不确定它是否正是您所需要的。如果您提供更多背景信息,我们可能会帮助您为您的具体问题获得更好的答案。
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.