a = [-1, 17, 3, 101, -46, 51]
I want the sum of elements from an arbitrary start index to an arbitrary end index.
I can do this :
partial = sum(a[start:end+1])
But Python slice creates another list which consumes memory and might be time-inefficient.
Does Python offer a built-in function to sum a subarray efficiently ?
1