reduce()--what is it good for? (was: Re: reduce() anomaly?)
Francis Avila
francisgavila at yahoo.com
Wed Nov 5 17:41:07 EST 2003
"Alex Martelli" <aleax at aleax.it> wrote in message
news:3fbqb.97878$e5.3584611 at news1.tin.it...
> Stephen C. Waterbury wrote:
> If you want to abuse reduce at all costs for this purpose,
> reduce(lambda x, y: x.update(y) or x, l) might work.
Just out of curiosity, for what kind of problems do we find reduce to just
be the Right Way? I mean, summing a big list of numbers is fun and all, but
I never find any use for it otherwise. I *often* try to think if reduce
would be useful when I come across some collection-of-values manipulation
task, but usually one wants to repeat an operation on a whole set of values,
not reduce the set to one value.
So, are there any *non-trivial* and *unabusive* uses of reduce, where any
other way would be tedious, repetitive, slow, unclear, etc.? I'm very
curious to see them.
reduce--the black sheep of the functional-Python herd?
--
Francis Avila
More information about the Python-list
mailing list