boolean xor
Andrew Dalke
dalke at acm.org
Thu Jan 11 02:05:27 EST 2001
Rainer Deyke wrote:
>If you want to play that way, the previous version is also flawed:
>
>not ( (a and b) or (not (a or b)) )
>
>In any case except where both 'a' and 'b' are true, the truth
>value of 'a' is calculated twice.
True, but I didn't really say that. Here's a
recapitulation of the thread.
Aahz said he was using:
def xor(a,b):
return not ( (a and b) or (not (a or b)) )
Nicolas (ndev22 at yahoo.com) suggested instead using:
def xor(a,b):
return not(a==b)
I pointed out that Aahz's expression compares the truth value
of the object and doesn't compare things them directly, so
the proper form of Nicolas' code must use operator.truth.
You applied DeMorgan's law to my quote of Aahz's original
statement, to get:
def xor(a, b):
return (a or b) and not (a and b)
This was a backtrack on the thread and I was actually pointing
out the difference between your modified form of Aahz's
code and my corrected form of Nicolas's interpretation of
Aahz's.
Got it? :)
Andrew
dalke at acm.org
More information about the Python-list
mailing list