[Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin
Nick Coghlan
ncoghlan at gmail.com
Sun Apr 8 01:39:04 EDT 2018
On 6 April 2018 at 02:52, Peter O'Connor <peter.ed.oconnor at gmail.com> wrote:
> Combined with the new "last" builtin discussed in the proposal, this would
> allow u to replace "reduce" with a more Pythonic comprehension-style syntax.
I think this idea was overshadowed by the larger syntactic proposal in
the rest of your email (I know I missed it initially and only noticed
it in the thread subject line later).
With the increased emphasis on iterators and generators in Python 3.x,
the lack of a simple expression level equivalent to "for item in
iterable: pass" is occasionally irritating, especially when
demonstrating behaviour at the interactive prompt.
Being able to reliably exhaust an iterator with "last(iterable)" or
"itertools.last(iterable)" would be a nice reduction function to
offer, in addition to our existing complement of builtin reducers like
sum(), any() and all().
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list