Re: [Tutor] Adding all numbers in a file or list

2010-08-24 Thread aug dawg
Got it. Thanks everyone! On Tue, Aug 24, 2010 at 6:22 PM, Steven D'Aprano wrote: > On Wed, 25 Aug 2010 02:23:10 am Nitin Das wrote: > > alternatively you can use the lambda , reduce function for summing up > > all the numbers in a list for e.g:- > > > > lis = [1,2,3,4,5] > > p = reduce(lambda x,

Re: [Tutor] Adding all numbers in a file or list

2010-08-24 Thread Steven D'Aprano
On Wed, 25 Aug 2010 02:23:10 am Nitin Das wrote: > alternatively you can use the lambda , reduce function for summing up > all the numbers in a list for e.g:- > > lis = [1,2,3,4,5] > p = reduce(lambda x,y : x+y, lis) > > p will have the value = 15. Sure, you *can* do this, by why would you re-inve

Re: [Tutor] Adding all numbers in a file or list

2010-08-24 Thread Shashwat Anand
On Tue, Aug 24, 2010 at 9:53 PM, Nitin Das wrote: > alternatively you can use the lambda , reduce function for summing up all > the numbers in a list for e.g:- > > lis = [1,2,3,4,5] > > p = reduce(lambda x,y : x+y, lis) > > p will have the value = 15. > Another approach, >>> lis = [1,2,3,4,5] >

Re: [Tutor] Adding all numbers in a file or list

2010-08-24 Thread Nitin Das
alternatively you can use the lambda , reduce function for summing up all the numbers in a list for e.g:- lis = [1,2,3,4,5] p = reduce(lambda x,y : x+y, lis) p will have the value = 15. --nitin On Mon, Aug 23, 2010 at 9:05 PM, aug dawg wrote: > Oh okay, sorry about that. > > Thanks for the

Re: [Tutor] Adding all numbers in a file or list

2010-08-23 Thread aug dawg
Oh okay, sorry about that. Thanks for the help! On Mon, Aug 23, 2010 at 11:33 AM, Sander Sweers wrote: > On 23 August 2010 17:24, aug dawg wrote: > > So it's sum(list_name) ? > > Correct, but it is not limited to lists. Any itterable with > ints/floats will do, for example a tuple is also acce

Re: [Tutor] Adding all numbers in a file or list

2010-08-23 Thread Sander Sweers
On 23 August 2010 17:24, aug dawg wrote: > So it's sum(list_name) ? Correct, but it is not limited to lists. Any itterable with ints/floats will do, for example a tuple is also accepted. Greets Sander PS: Please use reply to all so others on this list may benefit from the questions/answers ;-)

Re: [Tutor] Adding all numbers in a file or list

2010-08-23 Thread Sander Sweers
On 23 August 2010 17:13, aug dawg wrote: > Is there a command or module that I can use to add all the items in a list? > Alternatively, is there one I can use to add all the numbers in a file? sum() is what you are looking for [1]. Greets Sander [1] http://docs.python.org/library/functions.html