[Python-ideas] if in for-loop statement

Henk-Jaap Wagenaar wagenaarhenkjaap at gmail.com
Thu Feb 23 16:11:19 EST 2017


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 <rmartin at astek.fr> wrote:

> 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-53-15-05
> http://www.groupeastek.com/
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170223/5e553595/attachment.html>


More information about the Python-ideas mailing list