boolean xor
Rainer Deyke
root at rainerdeyke.com
Wed Jan 10 23:36:24 EST 2001
"Andrew Dalke" <dalke at acm.org> wrote in message
news:93iuj9$jta$1 at slb3.atl.mindspring.net...
>
> Rainer Deyke wrote:
> >You could, however, remove a redundant 'not' from the original:
> >
> >def xor(a, b): return (a or b) and not (a and b)
>
> That may find the truthness of a and b twice, which might
> not give the expected behaviour. Eg, if __nonzero__ takes
> time to compute (as with a proxy to a remote object) then
> the overhead may be twice as long.
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.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list