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,
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
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]
>
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
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
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 ;-)
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