boolean xor

Andrew Dalke dalke at acm.org
Wed Jan 10 19:28:04 EST 2001


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.

                    Andrew
                    dalke at acm.org







More information about the Python-list mailing list