Pythonic way to sum n-th list element?

Evan Simpson evan at 4-am.com
Fri Apr 18 16:39:02 EDT 2003
Guy Middleton wrote:
> 	>>> reduce(lambda a, b: a+b, [y[1] for y in x])
> 
> But I don't really like lambda, is there a better way to do this?

What's wrong with:

t = 0
for y in x:
     t += y[1]

The extra variable?  The number of lines?

Cheers,

Evan @ 4-am







More information about the Python-list mailing list