class GroupBySum:

    def __init__(self, maxsum):
        self.maxsum = maxsum
self.index = 0
self.sum = 0

def __call__(self, value):
    self.sum += value
if self.sum > self.maxsum:
    self.index += 1
self.sum = value
Split python tuple in subtuples with capacity limit in functional programming style