浏览列表中是否有True / False?

问题描述 投票:0回答:3

如果我有一个列表列表,那么如何遍历列表,如果一个元素为false,则返回值为False

a = [[True, True, True], [True, False, True]]

将返回

[True, False]
python
3个回答
2
投票

您想使用all功能。

[all(x) for x in a]

1
投票

您还可以使用map()代替列表理解:

map()

0
投票

a = [[True, True, True], [True, False, True]] result = list(map(all, a)) 与列表推导结合使用。

示例:

all()
© www.soinside.com 2019 - 2024. All rights reserved.