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 the degree of a node was < 2. Consider the following psuedocode:
vdict = g.degree_dict() #dictionary of nodes and their degrees
g.remove_from_nodes(v in g s.t. vdict[v] < 2)
I have seen some syntax that uses set theory notation but as I am still new to python I do not know how to use it. How do I convert this into working python code?