The condition for the collection of integers

how to write a short / neat logical condition for checking if all integers in a tuple are in a given range? Sort of

0 < (1,2,3) < 50 

would be ideal - of course, this did not work, because it uses lexicographic ordering, therefore also

 0 < (1,2,-3) < 50 

True. Instead, I would like it to evaluate True if and only if all numbers are in the range.

+4
source share
1 answer
 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.

+15
source

All Articles