Re: sum up numbers in a list

2008-08-26 Thread Terry Reedy
sharon kim wrote: is there a way to sum up all the numbers in a list? >>> help(sum) sum(...) sum(iterable[, start]) -> value Returns the sum of an iterable of numbers (NOT strings) plus the value of parameter 'start' (which defaults to 0). When the iterable is empty, return

Re: sum up numbers in a list

2008-08-26 Thread sharon kim
brilliant, thank you both of you, i will try that out later. :) On Wed, Aug 27, 2008 at 1:34 AM, c james <[EMAIL PROTECTED]> wrote: > >>> L=['10','15','20'] > >>> sum(int(x) for x in L) > 45 > > or > >>> sum(map(int,L)) > 45 > > > sharon kim wrote: > >> hi all, >> >> i have a list, for example;

Re: sum up numbers in a list

2008-08-26 Thread c james
>>> L=['10','15','20'] >>> sum(int(x) for x in L) 45 or >>> sum(map(int,L)) 45 sharon kim wrote: hi all, i have a list, for example; >>> L=[] >>> L.append('10') >>> L.append('15') >>> L.append('20') >>> len(L) 3 >>> print L ['10', '15', '20'] is there a way to sum up all the numbers in

Re: sum up numbers in a list

2008-08-26 Thread Fredrik Lundh
sharon kim wrote: i have a list, for example; >>> L=[] >>> L.append('10') >>> L.append('15') >>> L.append('20') >>> len(L) 3 >>> print L ['10', '15', '20'] is there a way to sum up all the numbers in a list? the number of objects in the list is vary, around 50 to 60. all objects are 1

sum up numbers in a list

2008-08-26 Thread sharon kim
hi all, i have a list, for example; >>> L=[] >>> L.append('10') >>> L.append('15') >>> L.append('20') >>> len(L) 3 >>> print L ['10', '15', '20'] is there a way to sum up all the numbers in a list? the number of objects in the list is vary, around 50 to 60. all objects are 1 to 3 digit positive