(lst, size)
Iterate through `lst` and yield batches of at most `size` items.

    Example:

    ```python
    >>> xs = [1, 2, 3, 4, 5]
    >>> list(batches(xs, size=2))
    [[1, 2], [3, 4], [5]]
    ```
Iterate through `lst` and yield batches of at most `size` items.
Iterate through lst and yield batches of at most size items .
def batches(lst, size):
    # type: (List[T], int) -> Iterator[List[T]]
    """
    Iterate through `lst` and yield batches of at most `size` items.

    Example:

    ```python
    >>> xs = [1, 2, 3, 4, 5]
    >>> list(batches(xs, size=2))
    [[1, 2], [3, 4], [5]]
    ```
    """
    if size <= 0:
        raise ValueError('Batch size must be > 0')

    for index in range(0, len(lst), size):
        yield lst[index : index + size]
def batches ( lst , size ) : # type: (List[T], int) -> Iterator[List[T]] if size <= 0 : raise ValueError ( 'Batch size must be > 0' ) for index in range ( 0 , len ( lst ) , size ) : yield lst [ index : index + size ]