Re: [Python-Dev] for loop with if filter

2007-11-16 Thread Paul Moore
On 16/11/2007, Gustavo Carneiro [EMAIL PROTECTED] wrote:
 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.

This should go to python-ideas, I guess. (FWIW, I can see the
attraction of the idea, but I don't think it's worth the cost in terms
of new syntax, subtle corner cases, etc etc).

Paul.
___
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


Re: [Python-Dev] for loop with if filter

2007-11-16 Thread Gustavo Carneiro
On 16/11/2007, Benji York [EMAIL PROTECTED] 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
___
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


Re: [Python-Dev] for loop with if filter

2007-11-16 Thread Benji York
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
-- 
Benji York
http://benjiyork.com
___
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


Re: [Python-Dev] for loop with if filter

2007-11-16 Thread martin
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  
[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

 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



___
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


[Python-Dev] for loop with if filter

2007-11-16 Thread Gustavo Carneiro
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
___
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


Re: [Python-Dev] for loop with if filter

2007-11-16 Thread Facundo Batista
2007/11/16, Gustavo Carneiro [EMAIL PROTECTED]:

 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.

The question is: is this slightly more verbosity and less clarity
worth enough as to make a syntax change in the language?

Personally, my answer is No.

-- 
.Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
___
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


Re: [Python-Dev] for loop with if filter

2007-11-16 Thread Terry Reedy

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


Re: [Python-Dev] for loop with if filter

2007-11-16 Thread Tristan Seligmann
* Terry Reedy [EMAIL PROTECTED] [2007-11-16 18:31:12 -0500]:

 
 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.

The extra level of indentation is awkward.
-- 
mithrandi, i Ainil en-Balandor, a faer Ambar


signature.asc
Description: Digital signature
___
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