mardi 31 mars 2015

Compressing multiple conditions in Python

Suppose I have a list of numbers mylist and that I would like execute some code if all the elements of mylist are greater than 10. I might try



if mylist[0] > 10 and mylist[1] > 10 and ... :
do something


but this is obviously this is a very cumbersome. I was wondering if Python has a way of compressing multiple conditions in an if statement. I tried



if mylist[i] > 10 for i in range(len(mylist)):
do something


but this returned an error.


I am using Python 3.4.


Aucun commentaire:

Enregistrer un commentaire