Ask Your Question

Revision history [back]

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

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