title: Convert BiDirectional Graph Edges to Undirected Edges in NetworkX
body: <p>I am using <a href="https://networkx.org/" rel="nofollow noreferrer">NetworkX</a> to do the following: I have a directed graph <em>g</em> that I want to
  transform into an undirected graph <em>h</em> such that <em>h</em> has the same nodes as <em>g</em> and <em>e</em>
  is an edge in <em>h</em> iff <em>e</em> is bidirectional in <em>g</em>. For example, I want to transform:</p>
  <pre><code>import networkx as nx
  g = nx.DiGraph([(&quot;A&quot;, &quot;B&quot;), (&quot;B&quot;, &quot;A&quot;), (&quot;A&quot;, &quot;C&quot;), (&quot;C&quot;, &quot;A&quot;), (&quot;B&quot;, &quot;C&quot;), (&quot;C&quot;, &quot;B&quot;), (&quot;A&quot;, &quot;D&quot;), (&quot;C&quot;, &quot;D&quot;), (&quot;B&quot;, &quot;E&quot;), (&quot;C&quot;, &quot;E&quot;)])
  </code></pre>
  <p><a href="https://i.stack.imgur.com/EJmzd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EJmzd.png" alt="directed graph" /></a></p>
  <p>into</p>
  <pre><code>h = nx.Graph([(&quot;A&quot;, &quot;B&quot;), (&quot;A&quot;, &quot;C&quot;), (&quot;B&quot;, &quot;C&quot;)])
  h.add_nodes_from([&quot;D&quot;, &quot;E&quot;])
  </code></pre>
  <p><a href="https://i.stack.imgur.com/M1yth.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M1yth.png" alt="undirected graph" /></a></p>
  <p>What <code>f(g) = h</code> should I write in NetworkX? I think it's some combination of graph
  views and filters, but I'm new to NetworkX so I'm not sure exactly what.</p>