A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-July/006229.html below:

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

[Python-Dev] zip() and list-comprehension with commasPaul 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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4