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

Paul Prescod paul@prescod.net
Wed, 12 Jul 2000 04:41:43 -0500


Peter Schneider-Kamp wrote:
> 
> 
> Would [x,y , for x in list1, if x > 1, if y > 2, for y in list2]
> be allowed? In other words: Should there be some rules of ordering?

Would this syntax make the answer clearer:

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

I don't think that makes sense unless y is externally bound.

> Would the following be allowed (and desirable)?
> y = 3
> [ x + y , for x in [1, 2, 3], if x > 1]
> producing [5, 6]

y = 3 
[for x in [1, 2, 3]:
	 if x > 1:
		x + y]

Sure, getting around Python's name binding "issues" is one of the (side)
benefits of list comprehensions.

-- 
 Paul Prescod - Not encumbered by corporate consensus
Simplicity does not precede complexity, but follows it. 
	- http://www.cs.yale.edu/~perlis-alan/quotes.html