I'd go for:
conds = iter([a, b, c])
if any(conds) and not any(conds):
# okay...
I think this should short-circuit fairly efficiently
Explanation
By making conds
an iterator, the first use of any
will short circuit and leave the iterator pointing to the next element if any item is true; otherwise, it will consume the entire list and be False
. The next any
takes the remaining items in the iterable, and makes sure than there aren't any other true values... If there are, the whole statement can't be true, thus there isn't one unique element (so short circuits again). The last any
will either return False
or will exhaust the iterable and be True
.
note: the above checks if only a single condition is set
If you want to check if one or more items, but not every item is set, then you can use:
not all(conds) and any(conds)