title: Filter NetworkX graph to list all edges coming from a nodes with specific attributes
body: <p>I have a NetworkX graph, with various node attributes loaded into the graph.  I would like to iterate through this graph, and first find all of the nodes that contain the attribute <code>'metric' : 'Top2'</code>.  Then once I have this list, I would like to the edges of all the 'Top2' nodes, and list out any edge that a 'Top2' node has to a node with the attribute <code>'city': 'Dallas'</code>'  </p>
  
  <p>I am able to successfully load my graph and attributes into NetworkX, but I can't seem to figure out how to get the node attribute filtering part figured out like I want to.  </p>
  
  <p><strong>Ultimately, I want to find any connections where a node with the attribute 'Top2' is in direct contact with a node with the attribute 'Dallas':</strong></p>
  
  <p><strong><em>Code</em></strong></p>
  
  <pre><code># import module
  import networkx as nx
  
  # create a blank graph
  g = nx.Graph()
  
  # add nodes with attributes to the graph
  n = [(u'A', {'city': 'Dallas'}),
       (u'C', {'city': 'Toledo'}),
       (u'B', {'city': 'Dallas'}),
       (u'E', {'city': 'Toldeo'}),
       (u'D', {'city': 'Lousiville', 'metric': 'Top2'}),
       (u'G', {'city': 'Lousiville'}),
       (u'F', {'city': 'Dallas', 'metric': 'Top2'})]
  
  e = [(u'A', u'B'),
       (u'C', u'B'),
       (u'B', u'D'),
       (u'E', u'D'),
       (u'E', u'G'),
       (u'E', u'F'),
       (u'D', u'G'),
       (u'D', u'F'),
       (u'G', u'F')]
  
  # add nodes and edges to the graph
  g.add_nodes_from(n)
  g.add_edges_from(e)
  
  # draw the graph
  nx.draw(g)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/HJfwZ.png" alt="&lt;code&gt;nx.draw(g)&lt;/code&gt;"></p>
  
  <pre><code># iterate through graph to identify all nodes with attribute 'metric' == 'Top2'
  Top2_nodes = []
  for n in g.nodes(data=True) if n[1]['metric'] == 'Top2'
      Top2_nodes.append(n)
  
  # iterate through 'Top2_nodes' to identify their connections to nodes with attribute 'city': 'Dallas'
  ...
  </code></pre>
  
  <p><strong>Ideally, the results would be formatted as follows:</strong></p>
  
  <pre><code>D,B
  D,F
  D,G
  </code></pre>