[Python-Dev] Re: Re: accumulator display syntax

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Oct 21 03:27:03 EDT 2003


> >     sum([lazy x*x for x in sequence])
>
> I like this the best of suggestions so far.  Easy to understand, easy
> to teach:
> [lazy ...] = iter([...]) but produced more efficiently

-1. An iterator is not a lazy list. A lazy list would support
indexing, slicing, etc. while calculating its items on demand.
An iterator is inherently sequential and single-use -- a
different concept.

But maybe some other keyword could be added to ease any
syntactic problems, such as "all" or "every":

  sum(all x*x for x in xlist)
  sum(every x*x for x in xlist)

The presence of the extra keyword would then distinguish
an iterator comprehension from the innards of a list
comprehension.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+



More information about the Python-Dev mailing list