On 24.02.2017 05:45, Chris Angelico wrote:
Don't forget that you can rewrite a "for-if" using two additional
lines and no indents, rather than one line and one indent:
for ...:
if not (...):
continue
...
...
That's exactly what I meant by "for+if+continue". At work we e
On Fri, Feb 24, 2017 at 3:28 PM, Steven D'Aprano wrote:
> There is nothing wrong with a nested for...if pair of statements. But
> that does take two lines, and two indents, rather than one:
>
> block
> for ...
> if ...
> block
>
> versus hypothetical:
>
> block
>
On Thu, Feb 23, 2017 at 11:07:49PM +0100, Sven R. Kunze wrote:
> >If the use of two lines and two indents is truly a problem, to the point
> >that you really need to refactor to a single line, that's a code smell:
> >your function is probably too big, too complex and does too much, and
> >should b
Hey Steven,
On 23.02.2017 19:25, Steven D'Aprano wrote:
Indeed not. The Pythonic solution is exactly the one you used: DON'T
combine the for-loop and if-statement.
for x in range(100):
if is_prime(x):
...
If the use of two lines and two indents is truly a problem, to the point
th
I think, in that particular example, that is an ok solution, however if you
are combining multiple booleans to create a lambda or separate function
that is quite a bit of syntactical sugar to add (unless it is re-used).
H-J
On 23 February 2017 at 18:11, Régis Martin wrote:
> Hello,
> why not us
Hello,
why not using the filter function?
for x in filter(is_prime, range(100)):
# do something with x
This is equivalent as was mentionned at first:
for x in range(100) if is_prime(x):
# do things with x
Régis
--
Régis Martin
Directeur de Projets Astek Industrie
Tel: 06-83-5
On Thu, Feb 23, 2017 at 01:37:15PM +, Henk-Jaap Wagenaar wrote:
[...]
> Other solutions to another case of this 'problem' are discussed has been
> discussed on StackOverflow (
> http://stackoverflow.com/questions/6981717/pythonic-way-to-combine-for-loop-and-if-statement)
> where it is suggeste
On Thu, Feb 23, 2017 at 03:33:32PM +, Paul Moore wrote:
> Ha. I never even *thought* of putting something like this in the
> devguide. Thanks for the pointer. I'll try to make some time to polish
> up my comments and put a PR together for that.
Paul, at the moment I have neither the time nor
On Thu, Feb 23, 2017 at 03:02:18PM +, Paul Moore wrote:
> We really need a FAQ for this, if there isn't one already.
Indeed.
Earlier this year, I started a thread on Things That Won't Change In
Python.
If I recall correctly, Nick disagreed that it should be a PEP, I started
to write up a
Hi Henk-Jaap,
thanks for your "if in for" proposal.
Paul's comments are all "motherhood statements" against a generic
proposal. It's nothing that would prevent your specific proposal from
being accepted or not. And there's no rejected PEP for this feature as
far as I can see.
Skimming throu
On 23 February 2017 at 15:18, Henk-Jaap Wagenaar
wrote:
> Thanks for typing that all out and taking the time to respond to my emails.
> I think as you say, it might be good to put this somewhere obvious.
>
> I did find https://docs.python.org/devguide/langchanges.html and
> http://www.curiouseffic
Hi Paul,
Thanks for typing that all out and taking the time to respond to my emails.
I think as you say, it might be good to put this somewhere obvious.
I did find https://docs.python.org/devguide/langchanges.html and
http://www.curiousefficiency.org/posts/2011/02/justifying-python-language-chang
One does not seem to be able to do this in a generator expression:
foo = (x for x in [1, 2] if True else [1, 2, 3])
gives a syntax error, however, adding parenthesis 'solves' this:
foo = (x for x in [1, 2] if True else [1, 2, 3])
In the for-loop version, either works. Though I guess this would
On 23 February 2017 at 14:20, Henk-Jaap Wagenaar
wrote:
>
> In a straw poll at the company I work at everyone was in favour, though they
> obviously are not in charge of implementing or changing documentation so
> that is easy for them to say, they've got no skin in the game. I don't know
> whethe
2017-02-23 5:37 GMT-08:00 Henk-Jaap Wagenaar :
>
> Hi all,
>
> Often I have typed something like
>
> for x in range(100) if is_prime(x):
> # do things with x
>
> to find that this does not work, instead resorting to:
>
> for x in range(100):
> if is_prime(x):
> #
Hi Paul, Daniel, others,
That is fair enough and the right amount of blunt.
Let me go through the points that were made in that thread (I have not
found any other threads, if someone links to them, I will go through them
as well):
-
From: https://mail.python.org/pipermail/python-dev/2007-No
Just as a reference, I think the most recent reincarnation of this thread
was:
https://mail.python.org/pipermail/python-ideas/2016-September/042270.html
On 23 February 2017 at 13:46, Paul Moore wrote:
> On 23 February 2017 at 13:37, Henk-Jaap Wagenaar
> wrote:
> > Note that this has been sugges
On 23 February 2017 at 13:37, Henk-Jaap Wagenaar
wrote:
> Note that this has been suggested before at least once
> (https://mail.python.org/pipermail/python-dev/2007-November/075257.html),
> and that thread itself suggests it has been suggested before and shutdown by
> Guido (though no source is g
Hi all,
Often I have typed something like
for x in range(100) if is_prime(x):
# do things with x
to find that this does not work, instead resorting to:
for x in range(100):
if is_prime(x):
# do things with x
or
for x in range(100):
if not is_pri
19 matches
Mail list logo