def iter_chunk(it, n):
""" Chunking an iterator into small chunk of size `n`
Note: this can be used to slice data into mini batches
"""
if not isinstance(it, Iterator):
it = iter(it)
obj = list(islice(it, n))
while obj:
yield obj
obj = list(islice(it, n))
评论列表
文章目录