在python中x或更大的值不在列表中时,如何运行while循环?

在python中x或更大的值不在列表中时,如何运行while循环?,python,while-loop,Python,While Loop,只要列表中有大于3的值,我就想运行while循环 例如: while 3 or greater not in list: run loop l = [4, 6, 2, 1, 0, 7, 9] while any(i >= 3 for i in l): l.remove(max(l)) print(l) 是否有任何技巧可以实现这一点,而不必创建另一个循环来检查这一点 谢谢 编辑: 谢谢你的建议。我实际上是在检查2D numpy数组。我最后把它做成这样: tilemap =

只要列表中有大于3的值,我就想运行while循环

例如:

while 3 or greater not in list:
    run loop
l = [4, 6, 2, 1, 0, 7, 9]
while any(i >= 3 for i in l):
    l.remove(max(l))
print(l)
是否有任何技巧可以实现这一点,而不必创建另一个循环来检查这一点

谢谢

编辑:

谢谢你的建议。我实际上是在检查2D numpy数组。我最后把它做成这样:

tilemap = np.zeros((mapheight, mapwidth), dtype = np.int)

while max(tilemap.ravel()) > 3:
    run loop

您可能正在寻找以下内容:

while any(i >= 3 for i in l):
    # Do something
例如:

while 3 or greater not in list:
    run loop
l = [4, 6, 2, 1, 0, 7, 9]
while any(i >= 3 for i in l):
    l.remove(max(l))
print(l)
剩下的

[2, 1, 0]

确保用编程语言标记问题。否则很难给你一个具体的答复。你看过那门语言的基本教程了吗?我也注意到了,谢谢。我环顾四周,但什么也找不到。你考虑过使用内置函数吗?