[Python-Dev] Re: accumulator display syntax

David Eppstein eppstein at ics.uci.edu
Fri Oct 17 13:15:10 EDT 2003


In article <16272.6895.233187.510629 at montanaro.dyndns.org>,
 Skip Montanaro <skip at pobox.com> wrote:

> I'm not in a mood to try and explain anything in more precise terms this
> morning (for other reasons, it's been a piss poor day so far) and must trust
> your ability to infer my meaning.  I have no idea at this point how to
> interpret
> 
>     foo[x*x for x in bar]
> 
> That looks like a syntax error to me.  You have a probably identifier
> followed by a list comprehension.

foo[ anything ] does not look like an identifier followed by a list, it 
looks like an indexing operation.  So I would interpret
    foo[x*x for x in bar]
to equal foo.__getitem__(i) where i is an iterator of x*x for x in bar.

In particular if iter.__getitem__ works appropriately, then
   iter[x*x for x in bar]
could be a generator comprehension and iter[1:n] could be an xrange.
Similarly sum and max could be given appropriate __getitem__ methods.

-- 
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