提交 9ce21848 authored 作者: Matthew Rocklin's avatar Matthew Rocklin

add remove utility function

上级 2daa77b1
import theano
from theano.gof.utils import give_variables_names, unique
from theano.gof.utils import give_variables_names, unique, remove
from theano.gof.python25 import all
......@@ -34,3 +34,8 @@ def test_give_variables_names_small():
give_variables_names(fgraph.variables)
assert all(var.name for var in fgraph.variables)
assert unique([var.name for var in fgraph.variables])
def test_remove():
even = lambda x: x % 2 == 0
odd = lambda x: x % 2 == 1
assert remove(even, range(5)) == filter(odd, range(5))
......@@ -410,3 +410,15 @@ def give_variables_names(variables):
"Maybe you've named some of the variables identically")
return variables
def remove(predicate, coll):
""" Return those items of collection for which predicate(item) is true.
>>> from itertoolz import remove
>>> def even(x):
... return x % 2 == 0
>>> remove(even, [1, 2, 3, 4])
[1, 3]
"""
return filter(lambda x: not predicate(x), coll)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论