self.sum = 0

def __call__(self, value):
    self.sum += value
if self.sum > self.maxsum:
    self.index += 1
self.sum = value
return self.index
for _, l in groupby((3, 1, 4, 2, 2, 1, 1, 2), GroupBySum(5)):
    pass
Split python tuple in subtuples with capacity limit in functional programming style