def filters(iterable, *predicates):
"""Filter the iterable on each given predicate.
>>> div_by_two = lambda x: not x % 2
>>> div_by_three = lambda x: not x % 3
>>> twos, threes = filters(range(10), div_by_two, div_by_three)
>>> list(twos)
[0, 2, 4, 6, 8]
>>> list(threes)
[0, 3, 6, 9]
"""
tees = tee(iterable, len(predicates))
return tuple(filter(pred, t) for pred, t in zip(predicates, tees))
评论列表
文章目录