from itertools import groupby
lst = [1, 2, 3, 5, 0, 0, 9, 45, 3, 0, 1, 7]
f = lambda x: x == 0
result = [i for k, g in groupby(lst, f) for i in (g if k else (sum(g),))]
print(result)
Суммируйте элементы списка между нулями в Python