> Is there a more pythonic way of doing this other than, 
> 
> if (a == b &
>     a == c &
>     a == d &
>     a == e &
>     a == f &
>     a == g):
>     do stuff

You don't want to use & coz its a bitwise comparison, 
so you should use 'and'....

if a == b and
   a == c and 
   ...

However you can also do the more intuitive:

if a == b == c == d == e == f == g:
   do stuff

Anther slightly mor flexible but much more obscure way 
uses comprehensions:

if [item for item in [a,b,c,d,e,f,g] if item != a]:

which returms an empty list(false0 if they are all equal.

The comprehensions advantage is that you can keep the 
list separate from the check and add, remove items and 
it doesn't break working code, each hard coded test 
would need to be modified in the event of a change.

Finally old assembler hackers will no doubt want to 
use xor:

if not (a^b^c^d^e^f):
   do it :-)

PS. The last works for primitive types but is not 
intended to be a serious suggestion!!

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to