Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use the all function:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading