[Python-ideas] Reduce/fold and scan with generator expressions and comprehensions
Chris Angelico
rosuav at gmail.com
Sun Oct 23 19:33:45 EDT 2016
On Mon, Oct 24, 2016 at 10:22 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> Right. But you're missing the point of Danilo's proposal. He isn't
> asking for a function to "jump to the end" of an iterator. Look at his
> example. The word "last" is a misnomer: he seems to me talking
> about having a special variable in comprehensions that holds the
> *previous* value of the loop variable, with special syntax to set its
> FIRST value, before the loop is entered. So "last" is a misleading name,
> unless you understand it as "last seen" rather than "very last, at the
> end".
>
Sounds like the PostgreSQL "lag" function [1]. Perhaps that's a better
name? Conceptually, what you have is another iteration point that lags
behind where you currently are.
ChrisA
[1] https://www.postgresql.org/docs/current/static/functions-window.html
More information about the Python-ideas
mailing list