[Tutor] Sum of List Elements

Luke Jordan luke.jordan at gmail.com
Sat Sep 24 19:25:07 CEST 2005

Thanks for the help everyone, for answering a simple question and pointing
me toward more resources.

On 9/24/05, bob <bgailer at alum.rpi.edu> wrote:
> At 08:11 AM 9/24/2005, Luke Jordan wrote:
> >Hi All,
> >
> >I have spent an embarrassingly large amount of time trying to solve what
> >on its face seems like a simple problem.
> >
> >I have a list of intergers, and I want to assign the sum of the intergers
> >in the list to a variable. There are only intergers in the list.
> In addition to the other solutions there is the (more generic?) use of the
> operator module and reduce function:
> import operator
> reduce(operator.add, (1,2,3))
> Explore operator to see what other functions you can use.
> Also there are the array handling modules such as numarray.
> You can also define your own classes based on list and write methods to do
> these operations.

"Whether you're an honest man, or whether you're a thief, depends on whose
solicitor has given me my brief. " - Benjamin Franklin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050924/67e2c045/attachment.htm

More information about the Tutor mailing list