[Python-Dev] zip() and list-comprehension with commas

Paul Prescod paul@prescod.net
Wed, 12 Jul 2000 06:21:56 -0500


Ka-Ping Yee wrote:
> 
> ...
>
> Does indentation matter, 

I'd say no. It is an expression in parens. Arguably, we could make the
actual line breaks optional also:

[for x in list1: if x > 1: for y in list2: if y > 2: (x,y)]

> and are you proposing blocks of "real" code in there?  

No. Just expressions.

> I suspect that writing it this way
> is going to tempt people to include more code, maybe expect
> to be able to write "else" clauses, put in "break", etc.

Miscomprehensions of this sort will not last long. It won't fail
silently!

else might be a useful extension. (future version!)

abs=[for x in nums: 
	if x>0: x
	else: -x]

There is the danger of introducing the ambiguous else.

> I think if you do it this way, the above is so close to how
> you'd write it without list comprehensions that it largely
> eliminates the succinctness that motivated list comprehensions
> in the first place.

It sounds like you are saying that the real benefit of list
comprehensions is that they allow you to avoid newlines! Anyhow, if you
don't like the newlines, I think we can make them optional without
losing anything. Then this syntax is as compact as the original.

The colon syntax is very clear about the fact that the lists are not
evaluated in parallel.
-- 
 Paul Prescod - Not encumbered by corporate consensus
Simplicity does not precede complexity, but follows it. 
	- http://www.cs.yale.edu/~perlis-alan/quotes.html