import itertools


def _split_doctest(code):
    """Split a single doctest string into multiple code block strings"""

    def is_code(x):
        return x.startswith(">>>") or x.startswith("...")

    groups = itertools.groupby(code.splitlines(), is_code)
    raw_code_blocks = (lines for is_code, lines in groups if is_code)
    code_blocks = ["\n".join(line[3:].strip() for line in lines) for lines in raw_code_blocks]
    return code_blocks