Sum of a list of integers
Perhaps this is common knowledge to everyone else, but it’s new to me. If you want to find the sum of a list of integers in Python:
import operators
sum = reduce(operator.add, list)
Pretty cool. Came in handy last night.
Update: As jpc points out below, you could also just use the built-in sum() function. Heh.
April 11th, 2006 at 1:18 pm
There is also a builtin function sum. :)
April 11th, 2006 at 10:21 pm
Heh, well that’s just too easy. ;)
BTW, congrats! Your comment is officially the 300th comment posted to the weblog (not including deleted spam). Yay!