missing 'xor' Boolean operator
Dr. Phillip M. Feldman
pfeldman at verizon.net
Wed Jul 15 14:19:18 EDT 2009
I did initially ask for an infix xor operator, but eventually gave up on
this. I like the first of your two one-line solutions below; this is clean
and easy to understand. Thanks! I'd still like to be able to write an
expression like '(a and b) xor (c and d) xor (e and f)', but it looks as
though that can't be done.
Well, that's not exactly what you originally asked for. But it's
still a one-liner:
def xor(*args): return bool(sum(map(bool, args)) % 2)
def xor(*args): return bool(len(filter(None, args)) & 1)
View this message in context: http://www.nabble.com/missing-%27xor%27-Boolean-operator-tp24485116p24503248.html
Sent from the Python - python-list mailing list archive at Nabble.com.
More information about the Python-list