Utility function to split iterable `f` into `n` chunks

def chunker(f, n):
    """
    Utility function to split iterable `f` into `n` chunks
    """
    f = iter(f)
    x = []
    while 1:
        if len(x) < n:
            try:
                x.append(f.next())
            except StopIteration:
                if len(x) > 0:
                    yield tuple(x)
                break
        else:
            yield tuple(x)
            x = []