Pythonic way to sum n-th list element?

Alex Martelli aleax at aleax.it
Sun Apr 20 03:45:49 EDT 2003


Steven Taschuk wrote:
   ...
> On reflection, I realize that I have prior experience (from math
> reading and play) with many concrete examples of what reduce
> abstracts: big sigma notation for sums, big pi notation for
> products, similar notations for set unions and intersections,

However, big-Sigma (by far the most used of all of these) is
exactly equivalent to the new, simple 'sum' function I propose,
NOT to the generality of the higher-order-function reduce.

> etc..  Familiarity with these concrete examples makes the
> abstraction of reduce sit very comfortably.  "I see, reduce turns
> + into big sigma."  But perhaps such familiarity is not typical in
> Python's, er, target market.

I think the familiarity with SPECIFIC bulk-functions, big-sigma
first and foremost, is quite good.  A higher order function that
abstracts them all, and more, is quite a different issue IMHO --
it does require a penchant for abstract thinking, like so much
of functional programming does.  We claim (an old slogan but
still good) that "Python fits your brain" -- if we want to be
sincere when saying this to "ordinary programmers off the street",
then we should take care not too place an excessive emphasis on 
the generality of functional programming to the detriment of
clarity and simplicity for ordinary operations such as "sum up
these numbers".


Alex






More information about the Python-list mailing list