"Gustavo Carneiro" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|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

Why write it backwards?

for r in results:
  if r.numNodes == numNodes
    # do something with r

is the direct parallel with the below code.

| 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

Same as above with ':\n' deleted.  A trivial difference.
An optional if clause is *less* flexible than an optional if statement and 
block.

| Has this idea come up before?  Does anyone else like this idea?

Yes, and Guido rejected at that time.

tjr
 



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to