def batch(iterable, chunk_size):
    """
    Return items from iterable in chunk_size bits.

    If len(iterable) % chunk_size > 0, the last item returned will be shorter.
    """
    i = iter(iterable)
    while True:
        r = list(itertools.islice(i, chunk_size))
        if not r:
            break
        yield r