[Python-Dev] Re: accumulator display syntax

David Eppstein eppstein at ics.uci.edu
Mon Oct 20 13:03:50 EDT 2003

In article <200310201640.h9KGe4I21305 at 12-236-54-216.client.attbi.com>,
 Guido van Rossum <guido at python.org> wrote:

> And in fact, I think that
>   sum(x for x in range(10))
> reads *better* than
>   sum of x for x in range(10)
> and certainly better than
>   sum of x for x in range of 10

I also think
    sum(x for x in range(10))
reads much better than
    sum(yield x for x in range(10))
    sum(yield: x for x in range(10))
or even
    sum([x for x in range(10)])

(The yield-based syntaxes also have the problem of confusing the reader 
into thinking the function containing them might be a generator.)
It is enough better that the "tuple comprehension" issue is a 
non-problem for me.  I'm assuming this syntax would need surrounding 
parens inside lists, tuples, and dicts (to avoid confusion with 
list/dict comprehensions and for the same reason [x,x for x in S] is 
currently invalid syntax) but avoiding the extra parens in other 
contexts like function calls looks like a win.

David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science

More information about the Python-Dev mailing list