How sum() should really be done

Douglas Alan nessus at mit.edu
Thu Nov 13 13:07:12 EST 2003


Douglas Alan <nessus at mit.edu> writes:

> Knowing about reduce() doesn't come from a LISP background, since it
> is uncommon to use reduce() in LISP.  There are few binary operators
> in LISP, so instead of doing reduce(+, seq), in LISP, you would
> typically do apply(+, seq).

Ah, that reminds me -- both sum() and reduce() can be removed from
Python by extending operator.add so that it will take any number of
arguments.  Then you can add up a sequence of numbers by doing
add(*seq).  The same thing goes for every other binary operator where
it makes sense to operate on more than two arguments at a time.

Now that's clean, simple, and powerful.

|>oug




More information about the Python-list mailing list