first = [0, 0, 0, 0]second = [0, 0, 0, 0]third = [0, 0, 0, 0]fourth = [0, 0, 0, 0]while 0 in first and 0 in second and 0 in third and 0 in fourth:顶部的列表以每个值保持为0开头。随着程序的进行,我计划将列表中的值从0更改为其他数字。有效地,我想知道是否有方法可以重写'while'语句以检查0是否在任何列表中,而没有'while not in __ and not in __'等长链。
3 回答

忽然笑
TA贡献1806条经验 获得超5个赞
while all(0 in i for i in [first,second,third,fourth]): ...
如果要检查列表中是否包含0,请执行以下操作:
while any(0 in i for i in [first,second,third,fourth]): ...

慕的地6264312
TA贡献1817条经验 获得超6个赞
您可以串联/合并所有列表并检查真实性:
while not all(first+second+third+fourth):
这将检查任何False-y值,如果为0,则返回True。
添加回答
举报
0/150
提交
取消