Lists of lists traversal
Alexander Williams
thantos at chancel.org
Wed Dec 22 18:57:21 EST 1999
On 22 Dec 1999 16:45:22 -0500, Justin Sheehy <dworkin at ccs.neu.edu> wrote:
>Your description above doesn't give me a very clear idea of what you
>are trying to do. The following function, given a list of lists of
>numbers, will return a list of their sums:
>
>>>> def Sum(ls):
>... from operator import add
>... newls = []
>... for i in ls:
>... newls.append(reduce(add, i))
>... return newls
>...
Or, more succinctly:
>>> import operator
>>> def Sum2(ls):
>>> return map(lambda l: reduce(operator.add, l),
>>> ls)
The horrifying need to use a lambda in here is one more scream amongst
the wasteland for automatically curried functions. :)
--
Alexander Williams (thantos at gw.total-web.net) | In the End,
"Join the secret struggle for the soul of the world." | Oblivion
Nobilis, a new Kind of RPG | Always
http://www.chancel.org | Wins
More information about the Python-list
mailing list