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

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

    Don't use list as a variable name, it shadows the builtin list(). There is a builtin function called any which is useful here

    if any(x>70 for x in the_list):
    

    The part inbetween the ( and ) is called a generator expression

提交回复
热议问题