[Tutor] Adding all numbers in a file or list

Nitin Das nitin.162 at gmail.com
Tue Aug 24 18:23:10 CEST 2010


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 <augdawg09 at gmail.com> wrote:

> Oh okay, sorry about that.
>
> Thanks for the help!
>
>
>
> On Mon, Aug 23, 2010 at 11:33 AM, Sander Sweers <sander.sweers at gmail.com>wrote:
>
>> On 23 August 2010 17:24, aug dawg <augdawg09 at gmail.com> 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 ;-)
>>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100824/2eb00c11/attachment.html>


More information about the Tutor mailing list