Pythonic way to sum n-th list element?

Tim Gahnström /Bladerman tim at bladerman.com
Fri Apr 18 23:31:14 CEST 2003


"Evan Simpson" <evan at 4-am.com> wrote in
> 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?

I am really curious about that to, I would most definitley say that this is
the most pythonic way. It is simple and easily readabel by anyone and I am
sure it is just as fast any of the other way.

I am not complaining now, I am sure there is a good reason and I am just
curious.

Thanx,

Tiim







More information about the Python-list mailing list