How to compare all items in a list with an integer without using for loop

前端 未结 6 1953
臣服心动
臣服心动 2021-01-14 06:25

I have a couple of lists which vary in length, and I would like to compare each of their items with an integer, and if any one of the items is above said integer, it breaks

6条回答
  •  滥情空心
    2021-01-14 07:20

    You can use the built-in function any like this:

    for list in listoflists:
        if any(x < 70 for x in list):
            continue
    

    The any function does short-circuit evaluation, so it will return True as soon as an integer in the list is found that meets the condition.

    Also, you should not use the variable list, since it is a built-in function.

提交回复
热议问题