Pythonic way to sum n-th list element?
staschuk at telusplanet.net
Sun Apr 20 19:28:54 CEST 2003
Quoth Alex Martelli:
> 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".
I entirely agree. Your sum function optimizes both the
performance and the clarity of the common case.
What I was getting at is that imho an abstraction is easy to
understand if you are already familiar with several concrete
examples of it, and hard to understand if you are not. So if the
"ordinary programmer off the street" is familiar with only big
sigma (if that) then reduce will indeed seem a strange abstract
thing, and very unclear. But if they're familiar with a bunch of
similar notations, such as big pi and set operators, reduce will
seem more natural and clear.
This is an attempt to explain why I think reduce is clear, but
your teaching experience says it is not.
Steven Taschuk staschuk at telusplanet.net
"What I find most baffling about that song is that it was not a hit."
-- Tony Dylan Davis (CKUA)
More information about the Python-list