Reputation: 185
how do I write a concise/neat boolean condition to test if all the integers in a tuple are in a given range? Something like
0 < (1,2,3) < 50
would be perfect - of course that doesn't work because it uses lexicographical ordering, so also
0 < (1,2,-3) < 50
evaluates to True. Instead I would want it to evaluate to True if and only if all the numbers are in the range.
Upvotes: 4
Views: 219
Reputation: 46637
all(0 < n < 50 for n in thetuple)
should be a relatively concise solution. it may not be the shortest piece of code, but it is almost self-documenting.
Upvotes: 15