On Wed, Apr 11, 2018 at 1:41 PM, Steven D'Aprano <st...@pearwood.info> wrote:
> Personally, I still think the best approach here is a combination of
> itertools.accumulate, and the proposed name-binding as an expression
> feature:
>
>     total = 0
>     running_totals = [(total := total + x) for x in values]
>     # alternative syntax
>     running_totals = [(total + x as total) for x in values]
>
> If you don't like the dependency on an external variable (or if that
> turns out not to be practical) then we could have:
>
>     running_totals = [(total := total + x) for total in [0] for x in values]
>

Linking this to the PEP 572 thread, this is an open question now:

https://www.python.org/dev/peps/pep-0572/#importing-names-into-comprehensions

Anyone who's interested in (or intrigued by) this potential syntax is
very much welcome to hop over to the PEP 572 threads and join in.

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to