Yield successive n-sized chunks from an iterable.
166307
def chunks(iterable, chunk):
    """"""
    for i in range(0, len(iterable), chunk):
        yield iterable[i:i + chunk]
1178614
def list_chunks(l, n):
    
    if n < 1:
        n = 1
    return [l[i:i + n] for i in range(0, len(l), n)]
992162
def samples_to_batches(samples: Iterable, batch_size: int):
        """"""
        it = iter(samples)
        while True:
            with suppress(StopIteration):
                batch_in, batch_out = [], []
                for i in range(batch_size):
                    sample_in, sample_out = next(it)
                    batch_in.append(sample_in)
                    batch_out.append(sample_out)
            if not batch_in:
                raise StopIteration
            yield np.array(batch_in), np.array(batch_out)
961002
def split_seq(iterable, size):
    """"""
    elm = iter(iterable)
    item = list(itertools.islice(elm, size))
    while item:
        yield item
        item = list(itertools.islice(elm, size))
1075325
def groups_of(n, iterable):
    
    args = [iter(iterable)] * n
    for x in izip_longest(*args):
        yield [v for v in x if v is not None]
1367629
def iterate_chunks(i, size=10):
    
    accumulator = []

    for n, i in enumerate(i):
        accumulator.append(i)
        if (n+1) % size == 0:
            yield accumulator
            accumulator = []

    if accumulator:
        yield accumulator
532039
def chunks(seq, chunk_size):
    # type: (Sequence[T], int) -> Iterable[Sequence[T]]
    
    return (seq[i:i + chunk_size] for i in range(0, len(seq), chunk_size))
2551
def partition_all(n, iterable):
    
    it = iter(iterable)
    while True:
        chunk = list(itertools.islice(it, n))
        if not chunk:
            break
        yield chunk
375098
def _chunks(l, ncols):
    """"""
    assert isinstance(ncols, int), "ncols must be an integer"
    for i in range(0, len(l), ncols):
        yield l[i: i+ncols]
854133
def chunker(l, n):
    
    for i in ranger(0, len(l), n):
        yield l[i:i + n]
1240586
def chunked(iterable, n):

    
    iterable = iter(iterable)
    while 1:
        t = tuple(islice(iterable, n))
        if t:
            yield t
        else:
            return
1079404
def chunk_sequence(sequence, chunk_length):
    """"""
    for index in range(0, len(sequence), chunk_length):
        yield sequence[index:index + chunk_length]
1359762
def flatten(iterable):
    """"""
    # likely not used
    iterable = iter(iterable)
    while True:
        try:
            item = next(iterable)
        except StopIteration:
            break

        if isinstance(item, six.string_types):
            yield item
            continue

        try:
            data = iter(item)
            iterable = itertools.chain(data, iterable)
        except:
            yield item
1055191
def chunks(iterable, size):
    
    it = iter(iterable)
    item = list(islice(it, size))
    while item:
        yield item
        item = list(islice(it, size))
160844
def _chunk(iterable, size):
    """"""
    # We're going to use some star magic to chunk the iterable. We create a
    # copy of the iterator size times, then pull a value from each to form a
    # chunk. The last chunk may have some trailing Nones if the length of the
    # iterable isn't a multiple of size, so we filter them out.

    args = (iter(iterable),) * size

    return (
        # pylint: disable=star-args
        itertools.takewhile(lambda x: x is not None, group)
        for group in itertools.zip_longest(*args)
    )
1279320
def chunked(l, n):
    """"""
    return [l[i:i + n] for i in range(0, len(l), n)]
776046
def ibatch(iterable, size):
    """"""
    source = iter(iterable)
    while True:
        batch = itertools.islice(source, size)
        yield itertools.chain([next(batch)], batch)