<div dir="ltr">brilliant, thank you both of you, i will try that out later.<br><br>:)<br><br><div class="gmail_quote">On Wed, Aug 27, 2008 at 1:34 AM, c james <span dir="ltr"><<a href="mailto:cjames@callone.net">cjames@callone.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">>>> L=['10','15','20']<br>
>>> sum(int(x) for x in L)<br>
45<br>
<br>
or<br>
>>> sum(map(int,L))<br>
45<div><div></div><div class="Wj3C7c"><br>
<br>
sharon kim wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
hi all,<br>
<br>
i have a list, for example;<br>
<br>
 >>> L=[]<br>
 >>> L.append('10')<br>
 >>> L.append('15')<br>
 >>> L.append('20')<br>
 >>> len(L)<br>
3<br>
 >>> print L<br>
['10', '15', '20']<br>
<br>
is there a way to sum up all the numbers in a list?  the number of objects in the list is vary, around 50 to 60. all objects are 1 to 3 digit positive numbers.<br>
<br>
all i can think of is check the length of the list (in the above example, 3), then L[0]+L[1]+L[2] ......<br>
<br>
is there a better way to do the job? thanks.<br>
</blockquote>
<br></div></div><div><div></div><div class="Wj3C7c">
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div>