syntax question
From: AF (AnthonyF_at_Blarg.NET)
Date: 04/05/04
- Next message: Erik Max Francis: "Re: syntax question"
- Previous message: Garry Knight: "Re: Up to 80 percent off on medication, Python."
- Next in thread: Erik Max Francis: "Re: syntax question"
- Reply: Erik Max Francis: "Re: syntax question"
- Reply: Elaine Jackson: "Re: syntax question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Apr 2004 14:23:17 -0700
If I have a list of touples:
l = [(x1, y1), (x2, y2), ...]
Is there a 1 line way to extract and get the sum of each x and y
column. I can do it this way with 2 lines of code and iterating
through the list twice:
sumx = sum([x for x, y in l])
sumy = sum([y for x, y in l])
Is there a 1 liner way to get the sums of both x and y and only
iterate thru the list once?
Also, is there a way to extract a list of x's and a list of y's from
the touple list? 1 line of course.
Thanks!
AF
- Next message: Erik Max Francis: "Re: syntax question"
- Previous message: Garry Knight: "Re: Up to 80 percent off on medication, Python."
- Next in thread: Erik Max Francis: "Re: syntax question"
- Reply: Erik Max Francis: "Re: syntax question"
- Reply: Elaine Jackson: "Re: syntax question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|