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

Douglas Alan nessus at
Sat Nov 8 08:21:29 CET 2003

Alex Martelli <aleaxit at> writes:

> Existing, builtin functions _will_ be removed in 3.0: Guido is on record
> as stating that (at both Europython and OSCON -- I don't recall if he
> had already matured that determination at PythonUK time).  They
> exist for a reason, but when that reason is: "once upon a time, we
> thought (perhaps correctly, given the way the rest of the language and 
> library was at the time) that they were worth having", that's not 
> sufficient reason to weigh down the language forever with their 
> not-useful-enough weight.  The alternatives to removing those parts that 
> aren't useful enough any more are, either to stop Python's development 
> forever, or to make Python _bloated_ with several ways to perform the
> same tasks.  

I agree: Down with bloat!  Get rid of sum() -- it's redundant with
reduce(), which I use all the time, like so:

     def longer(x, y):
        if len(y) > len(x): return y
        else: return x

     def longest(seq):
        return reduce(longer, seq)

     print longest(("abc", "yumyum!", "hello", "goodbye", "?"))

  => yumyum!


More information about the Python-list mailing list