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 the for loop that it is in.
for list in listoflists:
if {anyiteminlist} > 70:
continue #as in skip to next list
{rest of code here}
Basically, I need to say: "If anything in this list is above 70, continue the loop with the next list"
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With