def filter_edges_by_attributes(graph, attr_key, attr_cond):
"""Filter graph edges by attributes.
Removes all the edges of the graph (inplace) that do not
satisfy `attr_cond`.
Parameters
----------
graph : networkx.(Di)Graph
attrs_key : attribute key
attrs_cond : callable
Condition for an attribute to satisfy: callable that returns
`True` if condition is satisfied, `False` otherwise.
"""
for (s, t) in graph.edges():
if (attr_key not in graph.edge[s][t].keys() or
not attr_cond(graph.edge[s][t][attr_key])):
graph.remove_edge(s, t)
评论列表
文章目录