util.py 文件源码

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

项目:open-synthesis 作者: twschiller 项目源码 文件源码
def partition(pred, iterable):
    """Use a predicate to partition entries into false entries and true entries."""
    # https://stackoverflow.com/questions/8793772/how-to-split-a-sequence-according-to-a-predicate
    # NOTE: this might iterate over the collection twice
    # NOTE: need to use filter(s) here because we're lazily dealing with iterators
    it1, it2 = itertools.tee(iterable)
    return itertools.filterfalse(pred, it1), filter(pred, it2)  # pylint: disable=bad-builtin
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号