syntax question

From: AF (AnthonyF_at_Blarg.NET)
Date: 04/05/04


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



Relevant Pages

  • Re: syntax question
    ... | If I have a list of touples: ... | Is there a 1 line way to extract and get the sum of each x and y ... I can do it this way with 2 lines of code and iterating ... is there a way to extract a list of x's and a list of y's from ...
    (comp.lang.python)
  • Re: syntax question
    ... > Is there a 1 line way to extract and get the sum of each x and y ... I can do it this way with 2 lines of code and iterating ... is there a way to extract a list of x's and a list of y's from ... \__/ I do this for the love of music / Not for the glitter and gold ...
    (comp.lang.python)
  • ADO Recordsets applications help needed
    ... I want to extract or filter data from parent data.I have limited knowledge of ... to make changes to the data.The data is combination of zero and non zero ... their sum, index,average, minimum and maximum. ... Arenden Matta ...
    (microsoft.public.access.modulesdaovba)
  • Re: How to do an Access Database Query in Excel
    ... This is the Macro I've recorded to do exactly what I manually do to extract ... Before it exports to Excel I wish it to SUM by Location ... each Item sales, so not sure where I would put that in the code below. ...
    (microsoft.public.excel.programming)
  • Re: How to return a value from a text in the word using VBA?
    ... I'm working with a multi-bookmarked document, and to name a bookmark I ... need to extract a number that is in a field in a table. ... Do you want code to sum the values? ...
    (microsoft.public.word.docmanagement)