I have a two-element tuple t
, each element is either a positive integer or None
, and the combination may be in one of the four 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 to treat 2) and 3) as one case, 1) as the second case, and 4) as the third case.
I want to find an operation on a given tuple to make it easier/more efficient to distinguish between the three cases. For example, t[0] or t[1]
will help us distinguish between the case of 2) and 3) and that of 4), but it cannot distinguish 2) and 3) from 1).
In the end, I want to minimize the number of if
checks needed.
Aucun commentaire:
Enregistrer un commentaire