[Python-Dev] PEP202

Greg Ewing greg@cosc.canterbury.ac.nz
Wed, 26 Jul 2000 14:49:16 +1200 (NZST)


Moshe Zadka said:

> [x; for x in seq]
>
> and 
>
> [x: for x in seq]

Having both the separator and the following 'for' looks
somewhat redundant to my eyes.

By the way, have people tried looking at some examples in
an editor with syntax highlighting? You may find that the
various parts stand out more clearly then -- I certainly
do.

> And what about
>
> [x+y for x in seq1 for y in seq2 if y>2 if x<3]
>
> or 
>
> [x+y for x in seq1 if x<3 for y in seq2 if y>2]
>
> What is allowed? 

Both are allowed, and both are useful. They produce the same
result, but the second one is more efficient. So you can either
write declaratively and not worry about the order, or if you're
concerned about speed, you can fine-tune the order of the
clauses.

> Aren't we being a bit too TIMTOWTDIish here?

No more than being able to say either

  x = (a+b); y = (c+d); h = sqrt(x*x + y*y)

or
 
  h = sqrt((a+b)*(a+b) + (c+d)*(c+d))

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+