[英]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. 评估为True。 Instead I would want it to evaluate to True if and only if all the numbers are in the range.
相反,当且仅当所有数字都在范围内时,我希望它评估为True。
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.
它可能不是最短的代码,但它几乎是自我记录的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.