[Tutor] checking for a condition across a list

Pijus Virketis virketis@fas.harvard.edu
Sun, 13 May 2001 21:50:39 -0400


Hi,

I know I posted this question already, but the list has been very busy, so
I hope it's not too obnoxious if I bring it up again ... Hopefully, there
is an obvious way I am missing. Here goes. Let's say I have a list: 

>>>myList = [1, 0, 1, 0, 0, 1, 1] 

How can I check for some condition across all the members of a list
simultaneously? In other words, how do I this say  more neatly: 

>>> if myList[0] == myList[1] == ... == myList[6] == 1: print "They're all
ones!" 

Thank you! 

Pijus
----------------------------------------------------------------------------
-------------------
Please have a look at my weblog at www.fas.harvard.edu/~virketis.