How to make a comparison of part of an array with one value

if x[3] > y and x[4] > y and x[5] > y and x[6] > y and x[7] > y and x[8] > y:

Do U have a more elegant method to compare it? actually, I have to compare one value with 30 values in the array, do U know a better way to write it?

>Solution :

You can use the all function:

if all(val > y for val in x[3:9]):
   # your code here

Leave a Reply