Pythonic way to sum n-th list element?
Evan Simpson
evan at 4-am.com
Fri Apr 18 16:39:02 EDT 2003
More information about the Python-list mailing list
Fri Apr 18 16:39:02 EDT 2003
- Previous message (by thread): Which documentation for 2.2?
- Next message (by thread): Pythonic way to sum n-th list element?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): Which documentation for 2.2?
- Next message (by thread): Pythonic way to sum n-th list element?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list