[Python-Dev] for loop with if filter
martin at martinthomas.net
martin at martinthomas.net
Fri Nov 16 17:11:25 CET 2007
I started thinking about itertools when I saw this then I realised
that your question was about changing the syntax to produce fewer
lines of code rather than writing more effiicient code.. seemed like a
case where you could use ifilter.
//Martin
are talking about cvhanging the syntax rQuoting Gustavo Carneiro
<gjcarneiro at gmail.com>:
> 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
>
> Has this idea come up before? Does anyone else like this idea?
>
> --
> Gustavo J. A. M. Carneiro
> INESC Porto, Telecommunications and Multimedia Unit
> "The universe is always one step beyond logic." -- Frank Herbert
>
More information about the Python-Dev
mailing list