title: python networkx remove nodes and edges with some condition
body: <p>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 &lt; 2. Consider the following psuedocode:</p>
  
  <pre><code>vdict = g.degree_dict()         #dictionary of nodes and their degrees
  g.remove_from_nodes(v in g s.t. vdict[v] &lt; 2)
  </code></pre>
  
  <p>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?</p>