[Question] Functional style with lists
David Berthelot
berthelo at lirmm.fr
Tue May 4 13:14:42 EDT 1999
Hi,
i like to program in functional style, for instance, to get the sum of
square values for a range i do :
>>> reduce(lambda x,y:x+y,map(lambda x:x*x,range(10)))
285
>>>
Ok, but i've a problem, how to access a list element in this fashion,
for instance:
>>> L = [ ("John",40), ("Monthy",35)]
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...
Does anybody has an idea to help me ?
--
- - --
David Berthelot Contact at:
3rd year PhD Student | LIRMM
Email: berthelo at lirmm.fr | 161, Rue Ada
Tel : 33 4 67 418 577 | 34392 MONTPELLIER Cedex 5
Fax : 33 4 67 418 500 | FRANCE
More information about the Python-list
mailing list