Mark Lawrence breamore...@yahoo.co.uk a écrit dans le message de
news:mailman.15070.1413978605.18130.python-l...@python.org...
Also would you please access this list via https://mail.python.org/mailman/listinfo/python-list or
read and action this
Michael Torrie wrote:
As far as I can tell, no BASIC dialect I've looked at (DOS and Linux
worlds only), has ever had any logical operators like AND (), OR (||),
and NOT (!). They only appear to have bitwise operators (,|,~ C
equivalent). The fact that comparison operators returned 0 and -1
On 10/26/2014 12:15 AM, Steven D'Aprano wrote:
Ben Finney wrote:
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
I suspect that Guido and the core developers disagree with you, since
they had the opportunity to fix that in Python 3 and didn't.
That doesn't follow; there are
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
Do you really not see the connection between counting and summing?
Connection? Of course. But I also see a huge distinction. I'm surprised
you could misunderstand my position to the extent you think such a
question needs to be asked.
On 2014-10-27 00:38, Ben Finney wrote:
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
Do you really not see the connection between counting and summing?
Connection? Of course. But I also see a huge distinction. I'm surprised
you could misunderstand my position to the extent you
On 26 October 2014 01:03, Ben Finney ben+pyt...@benfinney.id.au wrote:
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
I suspect that Guido and the core developers disagree with you, since
they had the opportunity to fix that in Python 3 and didn't.
That doesn't follow; there
On Sunday, October 26, 2014 9:45:22 AM UTC+5:30, Steven D'Aprano wrote:
http://legacy.python.org/dev/peps/pep-0285/
snipped
Ben Finney wrote:
I agree with the decision, because this isn't an issue which often leads
to *incorrect* code. But I maintain that it's an unfortunate and
Joshua Landau jos...@landau.ws writes:
Guido van Rossum answered Jul 28 '11 at 21:20,
http://stackoverflow.com/questions/3174392/is-it-pythonic-to-use-bools-as-ints
False==0 and True==1, and there's nothing wrong with that.
Guido is incorrect. I've already stated what's wrong.
That's
On Monday, October 27, 2014 7:59:04 AM UTC+5:30, Ben Finney wrote:
Joshua Landau writes:
Guido van Rossum answered Jul 28 '11 at 21:20,
http://stackoverflow.com/questions/3174392/is-it-pythonic-to-use-bools-as-ints
False==0 and True==1, and there's nothing wrong with that.
Guido is
On 27 October 2014 02:28, Ben Finney ben+pyt...@benfinney.id.au wrote:
Joshua Landau jos...@landau.ws writes:
Guido van Rossum answered Jul 28 '11 at 21:20,
http://stackoverflow.com/questions/3174392/is-it-pythonic-to-use-bools-as-ints
False==0 and True==1, and there's nothing wrong with
Joshua Landau jos...@landau.ws writes:
On 27 October 2014 02:28, Ben Finney ben+pyt...@benfinney.id.au wrote:
Guido is incorrect. I've already stated what's wrong.
You were arguing about what Guido thinks.
I don't know where I did that; to my knowledge, this is the first time
I've mentioned
On 10/25/14 1:03 AM, Steven D'Aprano wrote:
alister wrote:
On Fri, 24 Oct 2014 10:20:30 -0700, Dan Stromberg wrote:
On Fri, Oct 24, 2014 at 1:38 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
I don't get why that's considered hard to read.
So why is it hard to read when
On Sat, Oct 25, 2014 at 5:58 AM, Ned Batchelder n...@nedbatchelder.com wrote:
You mention standard Python idioms. I think this style of
conditional-via-indexing is becoming quite uncommon, and is no longer one of
the standard Python idioms. This is now in the category of outdated hack.
I
On Sat, 25 Oct 2014 16:03:16 +1100, Steven D'Aprano wrote:
[Alister]
I had to mentally step through this before it became apparent what it
was doing, can see places where it could be usefull (a switch
replacement) but it is not instantly obvious
Very little code is instantly obvious. Even
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
Of course it won't be clear to *everyone* but it should be clear
enough to people who are familiar with standard Python idioms. A
concrete example should be more obvious than the fake example:
title = ('Mr', 'Ms')[person.sex ==
On Sat, Oct 25, 2014 at 1:45 PM, Ben Finney ben+pyt...@benfinney.id.au wrote:
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
title = ('Mr', 'Ms')[person.sex == 'F']
which should be clear to anyone who understands indexing in Python and
that True == 1 and False == 0.
I consider
Dan Stromberg drsali...@gmail.com writes:
EG, if I have 3 mutually exclusive command line options, I'll do
something like:
if option_a + option_b + option_c != 1:
sys.stderr.write('{}: -a, -b and -c are mutually
exclusive\n'.format(sys.argv[0]))
That is an excellent illustration of why
On Sun, Oct 26, 2014 at 10:53 AM, Ben Finney ben+pyt...@benfinney.id.au wrote:
Dan Stromberg drsali...@gmail.com writes:
EG, if I have 3 mutually exclusive command line options, I'll do
something like:
if option_a + option_b + option_c != 1:
sys.stderr.write('{}: -a, -b and -c are
On 26/10/2014 01:01, Chris Angelico wrote:
On Sun, Oct 26, 2014 at 10:53 AM, Ben Finney ben+pyt...@benfinney.id.au wrote:
Dan Stromberg drsali...@gmail.com writes:
EG, if I have 3 mutually exclusive command line options, I'll do
something like:
if option_a + option_b + option_c != 1:
On Sun, Oct 26, 2014 at 11:09 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:
Horrible IMHO, it just doesn't fit in my mind set. Still each to their own.
Yeah, the comprehension version is way more explicit (though it
probably ought to be a set and a set comp, not a tuple and a list
comp), and
Ben Finney wrote:
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
Of course it won't be clear to *everyone* but it should be clear
enough to people who are familiar with standard Python idioms. A
concrete example should be more obvious than the fake example:
title = ('Mr',
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
I suspect that Guido and the core developers disagree with you, since
they had the opportunity to fix that in Python 3 and didn't.
That doesn't follow; there are numerous warts in Python 2 that were not
fixed in Python 3. As I
On 10/22/2014 09:46 PM, Gregory Ewing wrote:
Chris Angelico wrote:
I've seen much MUCH worse... where multiple conditional
expressions get combined arithmetically, and then the result used
somewhere...
In the days of old-school BASIC it was common to
exploit the fact that boolean
Ben Finney ben+pyt...@benfinney.id.au writes:
This is short and clear and needs no leaking of the underlying bool
implementation::
len(True for line in lines if line.strip())
Correction::
len([True for line in lines if line.strip()])
--
\ “Our task must be to free ourselves
On Sun, Oct 26, 2014 at 12:04 PM, Michael Torrie torr...@gmail.com wrote:
But you can run
into trouble if you tried to use a common python idiom like this:
x = read_some_lines() 'returns number of lines read, or zero if none are
if not x:
print (I couldn't read any lines)
On 10/25/2014 07:20 PM, Chris Angelico wrote:
So don't use Python idioms in BASIC. :) Back when I used to write
BASIC code, I'd do explicit comparisons with zero for this sort of
thing... these days, I'd use Python idioms, but I'd also write Python
code :)
I think it's indicative that the
Ben Finney wrote:
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
I suspect that Guido and the core developers disagree with you, since
they had the opportunity to fix that in Python 3 and didn't.
That doesn't follow; there are numerous warts in Python 2 that were not
fixed
On Sun, Oct 26, 2014 at 3:15 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Since the list items exist only to be counted, the actual item used makes no
difference. You could use any value at all, or even a different value each
time:
len([random.random() for line in lines
48K? Luxury!
ZX81 had an option for 64K
--
https://mail.python.org/mailman/listinfo/python-list
Marko Rauhamaa wrote:
BartC b...@freeuk.com:
Ah, but what would
x = [f, g][cond]()
produce?
It will select f or g (which should refer to functions), and call one of
those depending on cond. That's not a problem.
The problem is it will still evaluate both f and g,
That's not really
On Fri, Oct 24, 2014 at 7:38 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Of course one can write hard-to-read code using any idiom by sheer weight of
complexity or obfuscated naming:
value = [some_function(arg)[23]['key'] or
another_function.method((x +
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info:
So why is it hard to read when the index is a flag?
value = [f, g][cond]()
So, subjectively, which syntax would you prefer:
if j 10:
j += 1
else:
j = 3
or:
j = j + 1 if j 10 else 3
or:
j = (lambda: 3,
Marko Rauhamaa wrote:
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info:
So why is it hard to read when the index is a flag?
value = [f, g][cond]()
So, subjectively, which syntax would you prefer:
Depends on what else the code is doing. But my personal preference is a red
herring:
On Fri, Oct 24, 2014 at 1:38 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
I don't get why that's considered hard to read.
So why is it hard to read when the index is a flag?
value = [f, g][cond]()
It's clear to you, it's clear to me, but is it clear to everyone? I
very
On 10/22/2014 01:29 AM, ast wrote:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
Out of all of the replies, I don't think anyone
actually offered the answer:
a if condition else b
--
https://mail.python.org/mailman/listinfo/python-list
On Sat, Oct 25, 2014 at 4:23 AM, Tobiah t...@tobiah.org wrote:
Out of all of the replies, I don't think anyone
actually offered the answer:
a if condition else b
Jean-Michel did, the very first response.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
On Fri, Oct 24, 2014 at 7:07 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info if j 10:
j += 1
else:
j = 3
or:
j = j + 1 if j 10 else 3
or:
j = (lambda: 3, lambda: j + 1)[j 10]()
Certainly not the third one. That's needlessly obfuscated for
On 10/24/2014 10:27 AM, Chris Angelico wrote:
On Sat, Oct 25, 2014 at 4:23 AM, Tobiah t...@tobiah.org wrote:
Out of all of the replies, I don't think anyone
actually offered the answer:
a if condition else b
Jean-Michel did, the very first response.
ChrisA
I had to search for it.
Ian Kelly ian.g.ke...@gmail.com:
j = (lambda: 3, lambda: j + 1)[j 10]()
Yes, the lambda approach falls victim to function calls being slow.
That's just a deficiency in the compiler. There's nothing there that
prevents the optimizer from translating the expression into the
equivalent if
On Fri, 24 Oct 2014 10:20:30 -0700, Dan Stromberg wrote:
On Fri, Oct 24, 2014 at 1:38 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
I don't get why that's considered hard to read.
So why is it hard to read when the index is a flag?
value = [f, g][cond]()
It's clear to
alister alister.nospam.w...@ntlworld.com:
a = value if condition else another Value
is instantly obvious (at least to a native English speaker anyway)
And you can go further down that road. For example, you could say things
like:
die unless everything is OK
Marko
--
alister wrote:
On Fri, 24 Oct 2014 10:20:30 -0700, Dan Stromberg wrote:
On Fri, Oct 24, 2014 at 1:38 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
I don't get why that's considered hard to read.
So why is it hard to read when the index is a flag?
value = [f,
On Sat, Oct 25, 2014 at 4:03 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
Ha! And yet people have, and continue to, complain *bitterly* about the
non-standard ordering of Python's ternary if, compared to C, standard
if...else syntax, and English.
If the syntax is like C,
On 2014-10-23 04:46, Gregory Ewing wrote:
Chris Angelico wrote:
I've seen much MUCH worse... where multiple conditional
expressions get combined arithmetically, and then the result used
somewhere...
In the days of old-school BASIC it was common to
exploit the fact that boolean expressions
Dennis Lee Bieber wlfr...@ix.netcom.com wrote in message
news:mailman.15097.1414022143.18130.python-l...@python.org...
On Wed, 22 Oct 2014 19:08:40 +0100, BartC b...@freeuk.com declaimed the
following:
Comparing:
x = cond ? f() : g(); # C version
with
x = [f(), g()] [cond]
(Should
BartC b...@freeuk.com:
Ah, but what would
x = [f, g][cond]()
produce?
It will select f or g (which should refer to functions), and call one of
those depending on cond. That's not a problem.
The problem is it will still evaluate both f and g,
That's not really the problem. The problem
On Thu, Oct 23, 2014 at 7:44 AM, Marko Rauhamaa ma...@pacujo.net wrote:
However, the [f, g][cond]() technique is how pure lambda calculus
implements conditional branching so it is interesting in its own right.
I wasn't aware that lambda calculus had lists and indexing built in.
IOW, you can
Marko Rauhamaa ma...@pacujo.net writes:
BartC b...@freeuk.com:
x = [f, g][cond]()
It will select f or g (which should refer to functions), and call one of
those depending on cond. That's not a problem.
The problem is it will still evaluate both f and g,
That's not really the problem.
Alain Ketterlin al...@dpt-info.u-strasbg.fr:
j = (lambda: 3, lambda: j + 1)[j 10]()
This is just a way to delay evaluation *of the potential results*,
i.e., instill a bit of lazyness.
That's one way to characterize a function, or code in general.
That point of view is apparent in
- Original Message -
From: ast nom...@invalid.com
To: python-list@python.org
Sent: Wednesday, 22 October, 2014 10:29:43 AM
Subject: (test) ? a:b
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
j = 3 if j =10 else j+1
Cheers
JM
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
--
On Wed, Oct 22, 2014 at 8:05 PM, busca...@gmail.com wrote:
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
without not:
j = [j+1, 3][j=10]
with not:
j = [3,
On 22/10/2014 10:05, busca...@gmail.com wrote:
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
The
busca...@gmail.com a écrit dans le message de
news:7839376e-fc27-4299-ae63-4ddf17ef9...@googlegroups.com...
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
without
On Wed, Oct 22, 2014 at 8:16 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
The death penalty should be reintroduced into the UK for two crimes, writing
code like the above and using google groups.
No no no. Code like
On 10/22/14 5:05 AM, busca...@gmail.com wrote:
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
Why
On 22/10/2014 10:27, Chris Angelico wrote:
On Wed, Oct 22, 2014 at 8:16 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
The death penalty should be reintroduced into the UK for two crimes, writing
code like the above and
Ned Batchelder n...@nedbatchelder.com:
Why on earth would you recommend this outdated hack, when there's a
true conditional operator? [...] if someone asks for a conditional
operator, at least show them one!
No good deed goes unpunished.
Marko
--
On 22/10/2014 10:14, ast wrote:
busca...@gmail.com a écrit dans le message de
news:7839376e-fc27-4299-ae63-4ddf17ef9...@googlegroups.com...
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in
On Wednesday, October 22, 2014 5:01:08 PM UTC+5:30, Ned Batchelder wrote:
On 10/22/14 5:05 AM, buscacio wrote:
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
without
On Wed, 22 Oct 2014 12:41:49 +0100, Mark Lawrence wrote:
On 22/10/2014 10:27, Chris Angelico wrote:
On Wed, Oct 22, 2014 at 8:16 PM, Mark Lawrence
breamore...@yahoo.co.uk wrote:
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
The death penalty should be reintroduced
On Thu, Oct 23, 2014 at 2:12 AM, alister
alister.nospam.w...@ntlworld.com wrote:
Perhaps you're correct. Is there anything worse than looking at a
dreadful piece of code that makes no sense at all and knowing that you'd
written it six months earlier?
looking a a dreadful piece of unreadable
On Thu, 23 Oct 2014 02:18:42 +1100, Chris Angelico wrote:
On Thu, Oct 23, 2014 at 2:12 AM, alister
alister.nospam.w...@ntlworld.com wrote:
Perhaps you're correct. Is there anything worse than looking at a
dreadful piece of code that makes no sense at all and knowing that
you'd written it
On Wed, Oct 22, 2014 at 2:05 AM, busca...@gmail.com wrote:
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast escreveu:
Hello
Is there in Python something like:
j = (j = 10) ? 3 : j+1;
as in C language ?
thx
without not:
j = [j+1, 3][j=10]
with not:
j = [3,
Ned Batchelder wrote:
On 10/22/14 5:05 AM, busca...@gmail.com wrote:
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
Why on earth would you recommend this outdated hack, when there's a true
conditional operator?
j = 3 if j = 10 else j+1
I think that's a bit
On Thu, Oct 23, 2014 at 3:28 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
It's also a technique easily extensible to more than two
values:
'01TX'[n % 4]
is in my opinion more readable than:
i = n % 4
'0' if i == 0 else '1' if i == 1 else 'T' if i == 3 else
On 10/22/2014 05:45 AM, Mark Lawrence wrote:
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
Oh it's a trick !
thx
IMHO it's just dreadful. Why people insist on messing around like this
I really don't know, it just drives me nuts.
This actually was the standard
On Thu, 23 Oct 2014 03:28:48 +1100, Steven D'Aprano wrote:
Why on earth would you recommend this outdated hack, when there's a
true conditional operator?
j = 3 if j = 10 else j+1
I think that's a bit harsh. Especially since this appears to have been
Buscacio's first post here.
Rustom Mody rustompm...@gmail.com wrote in message
news:7d2ea3c1-504e-4f5c-8338-501b1483d...@googlegroups.com...
On Wednesday, October 22, 2014 5:01:08 PM UTC+5:30, Ned Batchelder wrote:
On 10/22/14 5:05 AM, buscacio wrote:
Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast
On 10/22/2014 12:40 PM, Chris Angelico wrote:
That's true when it's fundamentally arithmetic. But part of that
readability difference is the redundancy in the second one. What if it
weren't so redundant?
'Negative' if x 0 else 'Low' if x 10 else 'Mid' if x 20 else 'High'
You can't easily
On Thu, Oct 23, 2014 at 5:27 AM, Matthew Ruffalo mm...@case.edu wrote:
On 10/22/2014 12:40 PM, Chris Angelico wrote:
That's true when it's fundamentally arithmetic. But part of that
readability difference is the redundancy in the second one. What if it
weren't so redundant?
'Negative' if x
On 10/22/14 12:28 PM, Steven D'Aprano wrote:
Ned Batchelder wrote:
On 10/22/14 5:05 AM, busca...@gmail.com wrote:
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
Why on earth would you recommend this outdated hack, when there's a true
conditional operator?
j = 3
Michael Torrie wrote:
On 10/22/2014 05:45 AM, Mark Lawrence wrote:
without not:
j = [j+1, 3][j=10]
with not:
j = [3, j+1][not (j=10)]
Oh it's a trick !
thx
IMHO it's just dreadful. Why people insist on messing around like this
I really don't know, it just drives me nuts.
This
Chris Angelico wrote:
I've seen much MUCH worse... where multiple conditional
expressions get combined arithmetically, and then the result used
somewhere...
In the days of old-school BASIC it was common to
exploit the fact that boolean expressions evaluated
to 0 or 1 (or -1, depending on your
Dennis Lee Bieber wrote:
x = [f(), g()] [cond]
the latter evaluates both f() and g() instead of just one. Apart from
being inefficient, it can have unintended side-effects.
Ah, but what would
x = [f, g][cond]()
produce?
headache
--
By ZeD
--
75 matches
Mail list logo