def partition(iterable, predicate):
"""Divide the iterable into two iterables according to the predicate.
>>> evens, odds = partition(range(10), lambda x: not x % 2)
>>> list(evens)
[0, 2, 4, 6, 8]
>>> list(odds)
[1, 3, 5, 7, 9]
"""
t1, t2 = tee(iterable)
return filter(predicate, t1), filterfalse(predicate, t2)
评论列表
文章目录