utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Gilgamesh 作者: AndreaOrru 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号