[Python-Dev] Fwd: summing a bunch of numbers (or "whatevers")

Jack Diederich jack@performancedrivers.com
Sun, 20 Apr 2003 10:58:07 -0400

I see two points

1 - it isn't obvious to many people to write
    reduce(operator.add, mylist, 0) # where '0' is just an appropriate default

2 - reduce() is slower than a special purpose function

#2 is fixable (see my earlier posts) and isn't the main argument of proponents.

To #1 I would argue for education about reduce().  We already have minor
style wars about map/filter versus list comps.  This would just add one more.

People would still have to learn about reduce() when they wanted the first
argument to be anything other than operator.add.

  reduce(operator.add, mylist, 0)
  sum(mylist, 0)

is a solution looking for a problem, IMO.  I know I would have to learn what
the to-be-named module of aliases does if people start to use them.  I'll be
selfish here, I don't want to learn em.  The proposed patch would be
equivilent to a one line alias, even if it is written more verbosely in C.
A one line alias for existing functionality sounds like TMTOWTDI to me.

I also don't want people having patch fights every time they see sum() or 
reduce() in code (re-submitting whichever version they prefer).

A possible solution could be a 'newbie' module that defined things like
'sum' with the canonical solution listed in the documentation.  It would be
a nice clear flag to readers of the code while allowing the noob to skip
reading the reduce() manpage.