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

前端 未结 6 1837
臣服心动
臣服心动 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:03

    If you're using python 2.5 or greater, you can use the any() function with list comprehensions.

    for list in listoflists:
      if any([i > 70 for i in list]):
        continue
    

提交回复
热议问题