A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-November/075259.html below:

[Python-Dev] for loop with if filter

[Python-Dev] for loop with if filter [Python-Dev] for loop with if filterGustavo Carneiro gjcarneiro at gmail.com
Fri Nov 16 15:35:56 CET 2007
On 16/11/2007, Benji York <benji at benjiyork.com> wrote:
>
> Gustavo Carneiro wrote:
> > I am finding myself often doing for loops over a subset of a list, like:
> >
> >         for r in results:
> >             if r.numNodes != numNodes:
> >                 continue
> >             # do something with r
> >
> > It would be nice if the plain for loop was as flexible as list
> comprehensions
> > and allowed an optional if clause, like this:
> >
> >         for r in results if r.numNodes == numNodes:
> >             # do something with r
>
> You can do the same today, sans sugar:
>
>      for r in (s for s in results if s.numNodes == numNodes):
>          # do something with r


Yes, I can do that, as well as I can use the 'continue' statement, but both
versions are slightly more verbose and less clear than what I propose.

-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20071116/28fd6ca5/attachment.htm 
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4