4

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.

nareto
  • 185
  • 1
  • 11

1 Answers1

15
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.

Alexander Gessler
  • 45,603
  • 7
  • 82
  • 122