[Python-Dev] accumulator display syntax

Raymond Hettinger python at rcn.com
Fri Oct 17 17:55:11 EDT 2003

> > Which is why I didn't like the 'sum[x for x in S]' notation much.

> Let it rest in peace, then.

Goodbye, weird __getitem__ hack!

> > Let's look for an in-line generator notation instead.  I like
> >
> >   sum((yield x for x in S))

> So do I, _with_ the mandatory extra parentheses and all, and in
> fact I think it might be even clearer with the extra colon that Phil
> had mentioned, i.e.
>     sum((yield: x for x in S))


[David Eppstein, in a separate note]
> Along with that confusion, (x*x for x in S) would look like a tuple 
> comprehension, rather than a bare iterator.

Phil's idea cleans that up pretty well:

	(yield: x*x for x in S)

This is no more tuple-like than any expression surrounded by parens.

Raymond Hettinger

More information about the Python-Dev mailing list