boolean xor

ndev42 at yahoo.com ndev42 at yahoo.com
Wed Jan 10 12:56:05 EST 2001


> I need a boolean (not bit-wise) xor function.  I've got the following
> function, but my logic skills are rusty enough that I'm wondering if
> this is the "right" way to do it (I've validated that it produces the
> correct outputs, at least):
>
> def xor(a,b):
>     return not ( (a and b) or (not (a or b)) )

A boolean xor is a detector of differences. Knowing that, you can
simply write:

def xor(a,b):
	return not(a==b)

Hope it helps,
--
Nicolas


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list