'itertools recipe: Collect data into fixed-length chunks or blocks'

def chunk(self, iterable, n, fillvalue=None):

    args = ([iter(iterable)] * n)
    return izip_longest(fillvalue=fillvalue, *args)
