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.)