简体   繁体   English

如何获取布尔值作为包含布尔值的python列表的列表的输出

[英]How to get boolean values as output on a list for a python list containing Boolean values

I have 3 Lists as below我有 3 个列表如下

enter code here

A = [True, True, True]

B = [True, True, True,True,True,True]

C = [True, False, True, True]

From the above lists i need to get output for each list as True if all the elements in the list are True else False Required Output [True,True,False]从上面的列表中,如果列表中的所有元素都为 True,我需要将每个列表的输出设为 True,否则为 False 必需的输出 [True,True,False]

all()这样做的(如果可迭代对象的所有元素都为真(或者如果可迭代对象为空),则返回 True):

print([all(A), all(B), all(C)])

See the functions all() and any() .查看函数all()any()

>>> lst = [True, False]
>>> any(lst)
True
>>> all(lst)
False

As you can see you want the " any() " function.如您所见,您需要“ any() ”函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM