chunk('ABCDEFG', 3) --> ABC DEF G

def chunk(iterable, size):
    """
    chunk('ABCDEFG', 3) --> ABC DEF G
    """
    # TODO: only used in gui.mainwindow(deprecated)
    iterator = iter(iterable)
    while size:
        result = []
        try:
            for i in range(size):
                elem = next(iterator)
                result.append(elem)
            yield tuple(result)
        except StopIteration:
            if result:
                yield tuple(result)
            return