Ask Your Question

Revision history [back]

click to hide/show revision 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.)

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