[Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

Danilo J. S. Bellini danilo.bellini at gmail.com
Sun Oct 23 12:10:42 EDT 2016


>
> Ah, that makes SIX existing solutions. Do we need a seventh?

It might have dozens of solutions, perhaps an infinity of solutions.
Brainfuck and assembly can be used, or even turing machine instructions...

But there should be one, and preferably only one, OBVIOUS way to do it.
Readability counts.

Reduce lost the built-in status on Python 3. Lambdas lost the decomposing
arguments like "lambda (a, b), c: a + b * c". Using a for loop section
inside a generator expression or list/set/dict comprehension allow the
decomposing arguments and doesn't need a function to be imported. Actually,
itertools.accumulate and functools.reduce have their parameters reversed,
and accumulate doesn't have a "start" parameter.

Actually, the example I give in this thread is about a fold/reduce trying
to show it's way simpler than the other solutions. I didn't paste here any
scan use case because I sent links with several use cases, should I paste
their contents here? The PyScanPrev link (https://github.com/
danilobellini/pyscanprev) has several use case examples (including some
just for a comparison with other possible solutions) and even have a full
rationale for this idea.

-- 
Danilo J. S. Bellini
---------------
"*It is not our business to set up prohibitions, but to arrive at
conventions.*" (R. Carnap)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161023/f1db8dae/attachment.html>


More information about the Python-ideas mailing list