def grouper(iterable, n):
"""Collect data into fixed-length chunks or blocks.
If len(iterable) % n != 0, the last chunk is simply cut.
Example:
grouper('ABCDEFG', 3) -> ABC DEF G
Args:
iterable: Any iterable object.
n: The length of the chunks.
Returns:
An iterator that returns the chunks.
"""
args = [iter(iterable)] * n
groups = zip_longest(*args, fillvalue=None)
return (filter(lambda el: el is not None, group) for group in groups)
评论列表
文章目录