Re: Check if a given value is out of certain range

2015-10-05 Thread Michiel Overtoom
Why not use a function? if outside(x, 0, 10): print("x has wrong value") else: print("x has good value") where 'outside' is defined as: def outside(value, lowerbound, upperbound): return value < lowerbound or value > upperbound Greetings, --

Re: Check if a given value is out of certain range

2015-10-05 Thread Mark Lawrence
On 05/10/2015 09:18, Michiel Overtoom wrote: Why not use a function? if outside(x, 0, 10): print("x has wrong value") else: print("x has good value") where 'outside' is defined as: def outside(value, lowerbound, upperbound): return value <

Re: Check if a given value is out of certain range

2015-10-05 Thread Marko Rauhamaa
Jussi Piitulainen : > Michiel Overtoom writes: > >> Why not use a function? >> >> >> if outside(x, 0, 10): >> print("x has wrong value") >> else: >> print("x has good value") >> >> >> where 'outside' is defined as: >> >> def

Re: Check if a given value is out of certain range

2015-10-05 Thread Jussi Piitulainen
Michiel Overtoom writes: > Why not use a function? > > > if outside(x, 0, 10): > print("x has wrong value") > else: > print("x has good value") > > > where 'outside' is defined as: > > def outside(value, lowerbound, upperbound): > return value < lowerbound or

Re: Check if a given value is out of certain range

2015-10-05 Thread Chris Angelico
On Mon, Oct 5, 2015 at 10:42 PM, Marko Rauhamaa wrote: > Why not use a fricking class framework: > > Then, we could simply have: > > if Range(IncludedEndpoint(0), IncludedEndpoint(10)).outside(x): > print("x has wrong value") > else: > print("x has good

Re: Check if a given value is out of certain range

2015-10-05 Thread Marko Rauhamaa
Chris Angelico : > On Mon, Oct 5, 2015 at 10:42 PM, Marko Rauhamaa wrote: >> Why not use a fricking class framework: >> >> Then, we could simply have: >> >> if Range(IncludedEndpoint(0), IncludedEndpoint(10)).outside(x): >> print("x has wrong

Re: Check if a given value is out of certain range

2015-10-04 Thread Rustom Mody
On Sunday, October 4, 2015 at 7:18:11 PM UTC+5:30, Steven D'Aprano wrote: > On Sat, 3 Oct 2015 10:12 pm, Laura Creighton wrote: > > > Actually, the fact that adults have more difficulty processing > > negations is one of the earliest things proven experimentally > > in experimental psychology. >

Re: Check if a given value is out of certain range

2015-10-04 Thread Rustom Mody
On Monday, October 5, 2015 at 7:58:34 AM UTC+5:30, Rustom Mody wrote: > On Sunday, October 4, 2015 at 7:18:11 PM UTC+5:30, Steven D'Aprano wrote: > > and some negations may technically be harder to understand, but in a > > practical sense the difference may be negligible: > > > > if x == 1:

Re: Check if a given value is out of certain range

2015-10-04 Thread Steven D'Aprano
On Sat, 3 Oct 2015 10:12 pm, Laura Creighton wrote: > Actually, the fact that adults have more difficulty processing > negations is one of the earliest things proven experimentally > in experimental psychology. I don't think I've questioned that under some circumstances some negations can be

Re: Check if a given value is out of certain range

2015-10-03 Thread Steven D'Aprano
On Fri, 2 Oct 2015 07:45 am, John Gordon wrote: > In <87r3le1ht3@elektro.pacujo.net> Marko Rauhamaa > writes: [...] >> Wouldn't > >>x < 0 or 10 < x > >> be even more visual? > > I don't know what you mean by "more visual". > > In my opinion, when comparing a

Re: Check if a given value is out of certain range

2015-10-03 Thread Steven D'Aprano
On Sat, 3 Oct 2015 10:12 pm, Laura Creighton wrote: > People think logically LOL :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Check if a given value is out of certain range

2015-10-03 Thread Laura Creighton
Actually, the fact that adults have more difficulty processing negations is one of the earliest things proven experimentally in experimental psychology. Clark, H., & Chase, W. (1972). On the process of comparing sentences against pictures. Cognitive Psychology, 3, 472–517. is one of the most

Re: Check if a given value is out of certain range

2015-10-03 Thread Bartc
On 03/10/2015 11:29, Steven D'Aprano wrote: On Fri, 2 Oct 2015 07:45 am, John Gordon wrote: I find this discussion about the relative readability of not 0 <= x <= 10 #1 versus 0 < x or x > 10 #2 0 < x or 10 < x to be a good example of people's propensity to invent so-called "rational"

Re: Check if a given value is out of certain range

2015-10-02 Thread Ian Kelly
On Thu, Oct 1, 2015 at 3:45 PM, John Gordon wrote: > In <87r3le1ht3@elektro.pacujo.net> Marko Rauhamaa > writes: > >> > I wasn't commenting directly to the "ask not..." quote; I was >> > referring upthread to the choice between >> > >> > not 0 <= x <=

Re: Check if a given value is out of certain range

2015-10-01 Thread Laura Creighton
In a message of Thu, 01 Oct 2015 09:40:58 +0200, Laura Creighton writes: >'Either' doesn't get used much unless you are heading for >'either x or y but not both'. I don't think I was clear in expressing things this way. What I meant was, around here at any rate, 'either' is more often used for

Re: Check if a given value is out of certain range

2015-10-01 Thread Laura Creighton
In a message of Wed, 30 Sep 2015 14:46:48 -0600, Ian Kelly writes: >Thought mirrors language. In English, we typically would say "x is not >between 0 and 10", not "x is either less than 0 or greater than 10". I wonder if that is regional. I think you may have stacked things with the 'either' and

Re: Check if a given value is out of certain range

2015-10-01 Thread Ian Kelly
On Thu, Oct 1, 2015 at 2:33 AM, alister wrote: > Why is it that the Phrase "Don't Panic" is strongly discouraged in > emergency situations? > > answer because the brain parses the statement as follows and focuses on > Panic instead of calm. > > Don't : I must not

Re: Check if a given value is out of certain range

2015-10-01 Thread Steven D'Aprano
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

Re: Check if a given value is out of certain range

2015-10-01 Thread Steven D'Aprano
On Fri, 2 Oct 2015 04:20 am, John Gordon wrote: > In <560d78e2$0$1618$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano > writes: > >> > 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

Re: Check if a given value is out of certain range

2015-10-01 Thread Steven D'Aprano
On Thu, 1 Oct 2015 06:46 am, Ian Kelly wrote: > On Wed, Sep 30, 2015 at 2:19 PM, alister > wrote: [...] >> the problem with 1 is the human brain is not particularity good with >> negatives*. >> to do not (some function) you first of all have to work out some

Re: Check if a given value is out of certain range

2015-10-01 Thread John Gordon
In <560d78e2$0$1618$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano writes: > > 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

Re: Check if a given value is out of certain range

2015-10-01 Thread John Gordon
In <560d8726$0$1602$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano writes: > > But it takes ever-so-slightly more effort to do so. > Slightly more effort than what alternative? How would you communicate the > idea of *not* asking for X without using the concept of

Re: Check if a given value is out of certain range

2015-10-01 Thread Emile van Sebille
On 10/1/2015 12:59 PM, Marko Rauhamaa wrote: John Gordon : I wasn't commenting directly to the "ask not..." quote; I was referring upthread to the choice between not 0 <= x <= 10 and x < 0 or x > 10 Both are of course understandable, but in my opinion, the

Re: Check if a given value is out of certain range

2015-10-01 Thread Marko Rauhamaa
John Gordon : > I wasn't commenting directly to the "ask not..." quote; I was > referring upthread to the choice between > > not 0 <= x <= 10 > > and > > x < 0 or x > 10 > > Both are of course understandable, but in my opinion, the latter one > takes slightly less effort

Re: Check if a given value is out of certain range

2015-10-01 Thread Chris Kaynor
On Thu, Oct 1, 2015 at 3:03 PM, Ian Kelly wrote: > On Thu, Oct 1, 2015 at 3:45 PM, John Gordon wrote: > > In <87r3le1ht3@elektro.pacujo.net> Marko Rauhamaa > > writes: > >> Wouldn't > > > >>x < 0 or 10 < x > > > >> be even more

Re: Check if a given value is out of certain range

2015-10-01 Thread John Gordon
In <87r3le1ht3@elektro.pacujo.net> Marko Rauhamaa writes: > > I wasn't commenting directly to the "ask not..." quote; I was > > referring upthread to the choice between > > > > not 0 <= x <= 10 > > > > and > > > > x < 0 or x > 10 > > > > Both are of course

Re: Check if a given value is out of certain range

2015-10-01 Thread Ian Kelly
On Thu, Oct 1, 2015 at 3:45 PM, John Gordon wrote: > In <87r3le1ht3@elektro.pacujo.net> Marko Rauhamaa > writes: >> Wouldn't > >>x < 0 or 10 < x > >> be even more visual? > > [SNIP] > > Another strike is that the code isn't consistent with itself; it

Re: Check if a given value is out of certain range

2015-10-01 Thread Mark Lawrence
On 01/10/2015 19:18, Steven D'Aprano wrote: 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

Re: Check if a given value is out of certain range

2015-10-01 Thread Ian Kelly
On Wed, Sep 30, 2015 at 2:19 PM, alister wrote: > On Wed, 30 Sep 2015 21:06:02 +0300, Marko Rauhamaa wrote: > >> Grant Edwards : >> >>> not (0 <= x <= 10) (I) >>> [...] >>>(x < 0) or (x > 10) (II) >>> [...] >>> IMO,

Re: Check if a given value is out of certain range

2015-10-01 Thread alister
On Wed, 30 Sep 2015 14:46:48 -0600, Ian Kelly wrote: > On Wed, Sep 30, 2015 at 2:19 PM, alister > wrote: >> On Wed, 30 Sep 2015 21:06:02 +0300, Marko Rauhamaa wrote: >> >>> Grant Edwards : >>> not (0 <= x <= 10) (I)

Re: Check if a given value is out of certain range

2015-10-01 Thread alister
On Thu, 01 Oct 2015 18:37:50 +1000, Chris Angelico wrote: > On Thu, Oct 1, 2015 at 6:33 PM, alister > wrote: >> The recommended phase is Stay calm >> >> Stay: ok dont change anything, whats next >> Calm ok I am calm that's alright then > > Yes,

Re: Check if a given value is out of certain range

2015-10-01 Thread Chris Angelico
On Thu, Oct 1, 2015 at 6:33 PM, alister wrote: > The recommended phase is Stay calm > > Stay: ok dont change anything, whats next > Calm > ok I am calm that's alright then Yes, because that always works. Okay. Alright. I'm calm. *throws

Re: Check if a given value is out of certain range

2015-09-30 Thread sohcahtoa82
On Tuesday, September 29, 2015 at 1:33:23 PM UTC-7, Mark Lawrence wrote: > On 29/09/2015 17:48, Rob Gaddi wrote: > > On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > > > >> Hi, > >> > >> I know there is an elegant way to check if a given value is within > >> certain range. > >>

Re: Check if a given value is out of certain range

2015-09-30 Thread Marko Rauhamaa
Grant Edwards : > not (0 <= x <= 10) (I) > [...] >(x < 0) or (x > 10) (II) > [...] > IMO, (I) is _more_ readable than (II) IMO, they're equally readable (except that you should drop the redundant parentheses from (II)). Marko --

Re: Check if a given value is out of certain range

2015-09-30 Thread BartC
On 29/09/2015 05:46, Laxmikant Chitare wrote: Hi, I know there is an elegant way to check if a given value is within certain range. Example - To check if x is between zero and ten, I can do 0 < x 10. That's not clear. Do you mean whether x is 1 to 9 inclusive? Because your contrary example

Re: Check if a given value is out of certain range

2015-09-30 Thread Luca Menegotto
Il 29/09/2015 23:04, Random832 ha scritto: How about x not in range(11)? Remember: simpler is better. -- Ciao! Luca -- https://mail.python.org/mailman/listinfo/python-list

Re: Check if a given value is out of certain range

2015-09-30 Thread alister
On Wed, 30 Sep 2015 21:06:02 +0300, Marko Rauhamaa wrote: > Grant Edwards : > >> not (0 <= x <= 10) (I) >> [...] >>(x < 0) or (x > 10) (II) >> [...] >> IMO, (I) is _more_ readable than (II) > > IMO, they're equally readable (except that you should

Re: Check if a given value is out of certain range

2015-09-30 Thread alister
On Tue, 29 Sep 2015 18:44:33 -0500, Tim Chase wrote: > On 2015-09-29 21:32, Mark Lawrence wrote: >> On 29/09/2015 17:48, Rob Gaddi wrote: >> >> Is there any similar elegant way to check if a value is out of >> >> certain range? >> >> Example - To check if x is either less than zero or greater

Re: Check if a given value is out of certain range

2015-09-30 Thread Mark Lawrence
On 30/09/2015 19:31, sohcahto...@gmail.com wrote: On Tuesday, September 29, 2015 at 1:33:23 PM UTC-7, Mark Lawrence wrote: On 29/09/2015 17:48, Rob Gaddi wrote: On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: Hi, I know there is an elegant way to check if a given value is

Re: Check if a given value is out of certain range

2015-09-30 Thread Grant Edwards
On 2015-09-30, alister wrote: > On Tue, 29 Sep 2015 18:44:33 -0500, Tim Chase wrote: > >> On 2015-09-29 21:32, Mark Lawrence wrote: >>> On 29/09/2015 17:48, Rob Gaddi wrote: >>> >> Is there any similar elegant way to check if a value is out of >>> >> certain

Re: Check if a given value is out of certain range

2015-09-30 Thread John Gordon
In alister writes: > I would stick with the OP's current solution > Readability Counts! I agree. 'if x < 0 or x > 10' is perfectly fine. -- John Gordon A is for Amy, who fell down the stairs

Re: Check if a given value is out of certain range

2015-09-29 Thread Chris Angelico
On Tue, Sep 29, 2015 at 2:46 PM, Laxmikant Chitare wrote: > Hi, > > I know there is an elegant way to check if a given value is within certain > range. > Example - To check if x is between zero and ten, I can do 0 < x 10. > > Is there any similar elegant way to check

Check if a given value is out of certain range

2015-09-29 Thread Laxmikant Chitare
Hi, I know there is an elegant way to check if a given value is within certain range. Example - To check if x is between zero and ten, I can do 0 < x 10. Is there any similar elegant way to check if a value is out of certain range? Example - To check if x is either less than zero or greater than

Re: Check if a given value is out of certain range

2015-09-29 Thread Rob Gaddi
On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > Hi, > > I know there is an elegant way to check if a given value is within > certain range. > Example - To check if x is between zero and ten, I can do 0 < x 10. > > Is there any similar elegant way to check if a value is out of

Re: Check if a given value is out of certain range

2015-09-29 Thread Mark Lawrence
On 29/09/2015 17:48, Rob Gaddi wrote: On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: Hi, I know there is an elegant way to check if a given value is within certain range. Example - To check if x is between zero and ten, I can do 0 < x 10. Is there any similar elegant way to

Re: Check if a given value is out of certain range

2015-09-29 Thread Ian Kelly
On Tue, Sep 29, 2015 at 3:04 PM, Random832 wrote: > How about x not in range(11)? That's fine as long as x is known to only take integral values. -- https://mail.python.org/mailman/listinfo/python-list

Re: Check if a given value is out of certain range

2015-09-29 Thread Emile van Sebille
On 9/29/2015 2:04 PM, Random832 wrote: On Tue, Sep 29, 2015, at 16:32, Mark Lawrence wrote: not (0 <= x <= 10) Yuck. How about x not in range(11)? x = 5.5 Emile -- https://mail.python.org/mailman/listinfo/python-list

Re: Check if a given value is out of certain range

2015-09-29 Thread Denis McMahon
On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > Is there any similar elegant way to check if a value is out of certain > range? What about: if not (0 < x < 10): -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list

Re: Check if a given value is out of certain range

2015-09-29 Thread Random832
On Tue, Sep 29, 2015, at 16:32, Mark Lawrence wrote: > On 29/09/2015 17:48, Rob Gaddi wrote: > > On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > > > >> Hi, > >> > >> I know there is an elegant way to check if a given value is within > >> certain range. > >> Example - To check if x

Re: Check if a given value is out of certain range

2015-09-29 Thread Ian Kelly
On Tue, Sep 29, 2015 at 9:14 PM, Steven D'Aprano wrote: > On Wed, 30 Sep 2015 01:08 pm, Random832 wrote: > >> Steven D'Aprano writes: >>> It's not fine. In Python 2, >>>... >>> Testing a numeric value within a certain range of values should be >>>

Re: Check if a given value is out of certain range

2015-09-29 Thread Tim Chase
On 2015-09-29 21:32, Mark Lawrence wrote: > On 29/09/2015 17:48, Rob Gaddi wrote: > >> Is there any similar elegant way to check if a value is out of > >> certain range? > >> Example - To check if x is either less than zero or greater than > >> ten? Right now I am using x < 0 or x > 10. > > > >

Re: Check if a given value is out of certain range

2015-09-29 Thread Random832
Steven D'Aprano writes: > It's not fine. In Python 2, >... > Testing a numeric value within a certain range of values should be constant > time and constant memory. It should be *fast*. Using range in Python 2 is > none of those things. I wasn't aware we were discussing

Re: Check if a given value is out of certain range

2015-09-29 Thread Steven D'Aprano
On Wed, 30 Sep 2015 01:08 pm, Random832 wrote: > Steven D'Aprano writes: >> It's not fine. In Python 2, >>... >> Testing a numeric value within a certain range of values should be >> constant time and constant memory. It should be *fast*. Using range in >> Python 2 is none

Re: Check if a given value is out of certain range

2015-09-29 Thread Steven D'Aprano
On Wed, 30 Sep 2015 07:07 am, Ian Kelly wrote: > On Tue, Sep 29, 2015 at 3:04 PM, Random832 wrote: >> How about x not in range(11)? > > That's fine as long as x is known to only take integral values. It's not fine. In Python 2, it's painfully slow and inefficient, both