On Tue, Aug 24, 2010 at 9:53 PM, Nitin Das <nitin....@gmail.com> 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]
>>> reduce(operator.add, lis)
15

However use sum() for this, which is the most obvious way to do it.


>
> --nitin
>
> On Mon, Aug 23, 2010 at 9:05 PM, aug dawg <augdaw...@gmail.com> wrote:
>
>> Oh okay, sorry about that.
>>
>> Thanks for the help!
>>
>>
>>
>> On Mon, Aug 23, 2010 at 11:33 AM, Sander Sweers 
>> <sander.swe...@gmail.com>wrote:
>>
>>> On 23 August 2010 17:24, aug dawg <augdaw...@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@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
~l0nwlf
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to