boolean xor
Alex Martelli
aleaxit at yahoo.com
Thu Jan 11 11:52:43 EST 2001
"Steve Holden" <sholden at holdenweb.com> wrote in message
news:Tbi76.10504$X3.66627 at e420r-atl1.usenetserver.com...
[snip]
> A possibly salient point which hasn't been explicitly stated in this
thread
> (but might have been, seventeen days ago, my aging memory and general
> decreptitude being what it is) is that the binary logical operators
> short-circuit, and return the value of the last operand they evaluated.
Even
Bingo -- I *was* starting to think I should post about that. For least-
astonishment purposes, I'd thus like the xor function to behave similarly:
return either A or B if at all possible (it may not be, of course, if
both A and B are true). E.g.,
def xor(A,B):
if not A: return B
if not B: return A
(perhaps too cutesy in the attempted symmetry and in relying on the
default fall-off-the-end to avoid an explicit return None...).
Alex
More information about the Python-list
mailing list