def grouper(iterable, n):
    """Collect data into chunks of at most n elements"""
    i = 0
    lst = []
    iterable = iter(iterable)
    while True:
        try:
            lst.append(next(iterable))
        except StopIteration:
            break
        if i > 0 and i % n == 0:
            yield lst
            lst = []
        i += 1
    if len(lst) != 0:
        yield lst
