Given a pair of integer values, I need to check if both are non-negative or both are negative.
The trivial way is:
def func(a, b):
return (a >= 0 and b >= 0) or (a < 0 and b < 0)
But I am looking for something "neater", which I believe to be possible, so I came up with this:
def func(a, b):
return (a >= 0) ^ (b >= 0) == 0
However, this one feels a little "obscure to the average reader".
Is there a cleaner way?