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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With