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,
--
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 <
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
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
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
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
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.
>
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:
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
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
On Sat, 3 Oct 2015 10:12 pm, Laura Creighton wrote:
> People think logically
LOL :-)
--
Steven
--
https://mail.python.org/mailman/listinfo/python-list
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
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"
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 <=
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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,
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)
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,
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
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.
> >>
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
--
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
>>>
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.
> >
> >
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
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
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
54 matches
Mail list logo