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

前端 未结 6 1838
臣服心动
臣服心动 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条回答
  •  -上瘾入骨i
    2021-01-14 07:04

    Using the builtin any is the clearest way. Alternatively you can nest a for loop and break out of it (one of the few uses of for-else construct).

    for lst in listoflists:
        for i in lst:
            if i > 70:
                break
        else:
            # rest of your code
            pass
    

提交回复
热议问题