def chunk_sequence(sequence, chunk_length, allow_incomplete=True):
    """Given a sequence, divide it into sequences of length `chunk_length`.

    :param allow_incomplete: If True, allow final chunk to be shorter if the
        given sequence is not an exact multiple of `chunk_length`.
        If False, the incomplete chunk will be discarded.
    """
    (complete, leftover) = divmod(len(sequence), chunk_length)
    if not allow_incomplete:
        leftover = 0

    chunk_count = complete + min(leftover, 1)

    chunks = []
    for x in range(chunk_count):
        left = chunk_length * x
        right = left + chunk_length
        chunks.append(sequence[left:right])

    return chunks
Given a sequence, divide it into sequences of length `chunk_length`.

    :param allow_incomplete: If True, allow final chunk to be shorter if the
        given sequence is not an exact multiple of `chunk_length`.
        If False, the incomplete chunk will be discarded.
    
rtv/packages/praw/helpers.py