I have a range of values (L,R,U,D) and two variables, d and newd, containing one of them. I need to check if d and newd are in the same subset (L,R or U,D) or not.
I know I can do this:
d in {'L','R'} and newd in {'U','D'} or d in {'U','D'} and newd in {'L','R'}
this indeed returns False if they both have values in L,R or U,D, and True otherwise. Still, I find it much reduntant. Some suggestions about a more DRY approach?
If you know that there are only two sets and that your values must be in one or the other, then you can simplify it to this:
Explanation:
==areTrue, so the expression returnsTrue.==areFalse, so the expression returnsTrue.==will returnFalseand the otherTrueso the result of the expression will beFalse.