| 1 | initial version |
What about this?
def f(x):
return sum([x[i] for i in range(len(x))])
(I just think it's easier to remember than the answer by DSM.)
| 2 | No.2 Revision |
What about this? Assume $x$ is a list. Then:
def f(x):
return sum([x[i] for i in range(len(x))])
sum(x)
(I just think it's easier to remember than the answer by DSM.)
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.