reduce()--what is it good for? (was: Re: reduce() anomaly?)

Erik Max Francis max at alcyone.com
Fri Nov 7 17:17:20 EST 2003


Alex Martelli wrote:

> However, so many of reduce's practical use cases are eaten up by sum,
> that reduce is left without real use cases to justify its existence.

Any reduction that doesn't involve summing won't be handled by sum. 
Flattening a list of (non-recursive) lists is a good example.  reduce is
already in the language; removing an existing, builtin function seems
totally inappropriate given that it's there for a reason and there will
be no replacement.

> But comparing plain Python code to a built-in that's almost bereft of
> good use cases, and finding the plain Python code _faster_ on such a
> regular basis, is IMHO perfectly legitimate.

reduce will be at least as fast as writing an explicit loop. 
Potentially more if the function object used is itself a builtin
function.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ A man cannot be comfortable without his own approval.
\__/  Mark Twain




More information about the Python-list mailing list