utils.py 文件源码

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

项目:tichu-tournament 作者: aragos 项目源码 文件源码
def prev_this_next(items):
    """
    Loop over a collection with look-ahead and look-back.

    From Thomas Guest, 
    http://wordaligned.org/articles/zippy-triples-served-with-python

    Seriously useful looping tool (Google "zippy triples")
    lets you loop a collection and see the previous and next items,
    which get set to None at the ends.

    To be used in layout algorithms where one wants a peek at the
    next item coming down the pipe.

    """

    extend = itertools.chain([None], items, [None])
    prev, this, next = itertools.tee(extend, 3)
    try:
        next(this)
        next(next)
        next(next)
    except StopIteration:
        pass
    return zip(prev, this, next)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号