Collect data into fixed-length chunks or blocks

    e.g:

        grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx

    Got it from https://docs.python.org/2/library/itertools.html#recipes
163932
def grouper(iterable, items, fillvalue=None):
    
    args = [iter(iterable)] * items
    return izip_longest(fillvalue=fillvalue, *args)
412562
def chunks(iterable, chunksize, cast=tuple):
    # type: (Iterable, int, Callable) -> Iterable
    
    it = iter(iterable)
    while True:
        yield cast(itertools.chain([next(it)],
                   itertools.islice(it, chunksize - 1)))
748602
def grouper(xs: Iterable, n: int, fillvalue=None):
    
    args = [iter(xs)] * n
    return zip_longest(*args, fillvalue=fillvalue)
813117
def chunk(iterator, max_size):
    
    gen = iter(iterator)
    while True:
        chunked = list()
        for i, item in enumerate(gen):
            chunked.append(item)
            if i >= max_size - 1:
                break
        if not chunked:
            return
        yield chunked
303138
def get_chunk_coords(self):
        
        chunks = []
        for x in range(32):
            for z in range(32):
                m = self.metadata[x,z]
                if m.is_created():
                    chunks.append({'x': x, 'z': z, 'length': m.blocklength})
        return chunks
1217996
def grouper(num, iterable, fillvalue=None):
    ""
    # grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx
    args = [iter(iterable)] * num
    return zip_longest(fillvalue=fillvalue, *args)
499572
def parameter_blocks(self):
        ''''''
        bytes = 4. + sum(g.binary_size() for g in self.groups.values())
        return int(np.ceil(bytes / 512))
474107
def _grouped(iterable, n):
        
        args = [iter(iterable)] * n
        return [[e for e in t if not e is None] for t in zip_longest(*args, fillvalue=None)]
125607
def _groups_of_size(iterable, n, fillvalue=None):
    """"""
    # _groups_of_size('ABCDEFG', 3, 'x') --> ABC DEF Gxx
    args = [iter(iterable)] * n
    return zip_longest(fillvalue=fillvalue, *args)
854133
def chunker(l, n):
    
    for i in ranger(0, len(l), n):
        yield l[i:i + n]
1082165
def grouper(iterable, n):
    
    it = iter(iterable)
    while True:
        chunk = itertools.islice(it, n)
        try:
            first = next(chunk)
        except StopIteration:
            return

        yield itertools.chain([first], chunk)
63157
def chunk_fill(iterable, size, fillvalue=None):
    
    # TODO: not used
    args = [iter(iterable)] * size
    return itertools.zip_longest(*args, fillvalue=fillvalue)
865378
def chunks(list_, count_items_in_chunk):
    
    for i in range(0, len(list_), count_items_in_chunk):
        yield list_[i:i + count_items_in_chunk]
548369
def chunk(iterable, chunk_size=20):
    """"""
    items = []
    for value in iterable:
        items.append(value)
        if len(items) == chunk_size:
            yield items
            items = []
    if items:
        yield items
1055380
def iter_chunks(chunk_size, iterator):
    ""
    iterator = iter(iterator)
    while True:
        next_chunk = _take_n(chunk_size, iterator)
        # If len(iterable) % chunk_size == 0, don't return an empty chunk.
        if next_chunk:
            yield next_chunk
        else:
            break
618221
def chunks(data, chunk_size):
    
    for i in xrange(0, len(data), chunk_size):
        yield data[i:i+chunk_size]
1048885
def get_chunks(Array, Chunksize):
    """"""
    for i in range(0, len(Array), Chunksize):
        yield Array[i:i + Chunksize]