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 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. 回答1: Your attempt is pretty close. You just