Check if a given value is out of certain range

Steven D'Aprano steve at pearwood.info
Thu Oct 1 14:18:08 EDT 2015


On Thu, 1 Oct 2015 08:31 am, Mark Lawrence wrote:

>> What is so "yuck" about that?  What would you do instead?  It seems like
>> the best solution to me.  Easy to read, fast to execute.
>>
> 
> I have to parse those damn brackets and then figure out the inverted
> logic. Give me x < 0 or x > 10 any day of the week.  When you're an old,
> senile git like me, readability counts :-)

With the greatest of respect Mark, I don't believe that for a second. Your
sig line, which you have used without fail for more years than I can
remember includes the phrase "ask not what our language can do for you". If
you can understand that, I don't believe that you cannot figure out how to
go from this:

# x is within the range a to b
a <= x < = b

to this:

# x is NOT within the range a to b
not a <= x < = b


You're certainly a senile old git if you think we're falling for that
one :-)



P.S. in case you missed it, you don't actually need the params, since the
precedence of not is lower than the other operators.



Did-I-include-sufficient-smileys-ly y'rs,


-- 
Steven




More information about the Python-list mailing list