python - Distinguish efficiently between different possible combinations in a tuple -
i have two-element tuple t, each element either positive integer or none, , combination may in 1 of 4 forms:
1: (x, y): e.g. (2, 3)
2: (x, x): e.g. (1, 1)
3: (x, none) (or equivalently, (none, x)) : e.g. (3, none) or (none, 5)
4: (none, none)
my application logic wants treat 2) , 3) 1 case, 1) second case, , 4) third case.
i want find operation on given tuple make easier/more efficient distinguish between 3 cases. example, t[0] or t[1] distinguish between case of 2) , 3) , of 4), cannot distinguish 2) , 3) 1).
in end, want minimize number of if checks needed.
this should do:
if t[0] or t[1]: if t[0] == t[1] or not (t[0] , t[1]): # 2-3rd case else: # 1st case else: # 4th case
Comments
Post a Comment