[Question] Functional style with lists
Andrew M. Kuchling
akuchlin at cnri.reston.va.us
Tue May 4 13:28:13 EDT 1999
David Berthelot writes:
>I would like to sum the numeric values by using map.
>I've tried this:
>>>> map(lamda x,y:x+y,map(L.getitem,(1,)*len(L)))
>But of course it doesn't work...
The reduce() built-in does this sort of thing. Try:
>>> reduce(lambda total,(name,amt): total + amt, L, 0)
75
--
A.M. Kuchling http://starship.python.net/crew/amk/
I'm an excuse for medical experiments and art theory. You must get me out of
here and out of the hospital.
-- Peter Greenaway, _A Zed and Two Noughts_ (1986)
More information about the Python-list
mailing list