def split_by(sequence, length):
    iterable = iter(sequence)

def yield_length():
    for i in range(length):
        yield next(iterable)
while True:
    res = list(yield_length())
if not res:
    return
yield res
Сегментировать список в Python