In the python library networkx I would like to remove the nodes and edges of a graph which have some property. For example, suppose I wanted to remove all nodes and edges where
If we have an initialized graph g
the following will set f
to be g
subject to the constraint that each vertex must have a degree > 0. We could easily generalize 0 with a variable:
f = nx.Graph()
fedges = filter(lambda x: g.degree()[x[0]] > 0 and g.degree()[x[1]] > 0, g.edges())
f.add_edges_from(fedges)