Skip to content

Snipe CLI Documentation

split_chunks(lst, n)

Splits the list lst into n nearly equal chunks. If n is zero or greater than the list length, returns the entire list as one chunk.

Source code in src/snipe/cli/cli_qc.py
def split_chunks(lst: List[str], n: int) -> List[List[str]]:
    """Splits the list `lst` into `n` nearly equal chunks. If n is zero or greater than the list length, returns the entire list as one chunk."""
    if n <= 0:
        n = 1
    if n > len(lst):
        n = len(lst)
    k, m = divmod(len(lst), n)
    return [lst[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n)]