semicolon at end of python's statements

Fábio Santos fabiosantosart at gmail.com
Fri Aug 30 06:32:17 EDT 2013


On 29 Aug 2013 23:20, "Ben Finney" <ben+python at benfinney.id.au> wrote:
>
> Fábio Santos <fabiosantosart at gmail.com> writes:
>
> > It is a shame that this is not possible in python. for..if exists in
> > comprehensions and not in regular loops but that would be nice
> > sometimes.
>
> So you use it in a generator expression, and iterate over the generator:
>
>     for foo in (spam for spam in sequence if predicate(spam)):
>         process(spam)
>
> That way, there's no need for new syntax.

The problem I have with that strategy is that it is repetitive and hinders
readability. You wrote "for" and "in" twice, and spam (a pretty useless
intermediate variable) thrice! While it does its job, it hides the true
intent for filtering beneath a lot of (pun intended) spam. The "if"
particle is nigh undetectable there.

To get around this, I often declare a generator. But I still find it a bit
awkward to have to look up the definition elsewhere, and to waste lines
over something so simple.

I can't say I understand why we don't merge the for loops' syntax with the
comprehension syntax. Even after following the for..while discussion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130830/fd4d4f0a/attachment.html>


More information about the Python-list mailing list