For subtraction you could loop yourself and subtract:
result = L[0]
for num in L[1:]:
result -= num
This presumes that you want to start with the first number and subtract all the other numbers from that first value.
You could still use sum()
but then you'd have to map()
all but the first number to negative:
from operator import neg
result = sum(map(neg, L[1:]), L[0])
The operator.neg()
function negates numbers, and we make use of the second argument to sum()
to provide a start value.
Demo:
>>> from operator import neg
>>> L = [42, 10, 3, 8]
>>> sum(map(neg, L[1:]), L[0])
21