Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

condition of tuple of integers

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.

like image 405
nareto Avatar asked Dec 06 '22 22:12

nareto


1 Answers

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.

like image 50
Alexander Gessler Avatar answered Dec 27 '22 01:12

Alexander Gessler