def possiblesplits(n, minsplits=2, maxsplits=0):
    """Returns lists of (index,length) tuples, representing all possible splits of a sequence of length n."""
    if not maxsplits: maxsplits = n
    for nrsplits in range(minsplits,maxsplits + 1):
        for split in sum_to_n(n,nrsplits):
            split_with_indices = []
            begin = 0
            for length in split:
                split_with_indices.append( (begin, length) )
                begin += length
            yield split_with_indices
Returns lists of (index,length) tuples, representing all possible splits of a sequence of length n.