Write a Graph into a file in an adjacency list form [mentioning all neighbors of each node in each line]
<p>I need to write a graph in a text file where each line of the file is composed from one node followed by all its neighbors. It's basically what an <a href="https://en.wikipedia.org/wiki/Adjacency_list" rel="nofollow">Adjacency List</a> is, and what the function <code>write_adjlist</code> is supposed to do. Unfortunatly it's not the case, as the edge are not replicated. In the exemple of wikipedia the adjacency list is :</p>

<blockquote>
  <p>a     adjacent to     b, c </p>
  
  <p>b     adjacent to     a, c</p>
  
  <p>c     adjacent to     a, b</p>
</blockquote>

<p>We can see that all edges are present two times (the edge <code>(a,b)</code> in lines 1 and 2, the edge <code>(b,c)</code> in lines 2 and 3...).</p>

<p>But now if I use the following code to generate a small world network :</p>

<pre><code>import networkx as nx

N=5  #Number of nodes
v=2  #Number of neighbours
p=.1 #rewiring proba

G = nx.connected_watts_strogatz_graph(N,v,p)
nx.write_adjlist(G.to_undirected(),"test.txt")
</code></pre>

<p>it gives me :</p>

<pre><code>#adj.py
# GMT Thu Jan 21 06:57:29 2016
# watts_strogatz_graph(5,2,0.1)
0 1 4
1 2
2 3
3 4
4
</code></pre>

<p>where I would like to have</p>

<pre><code>0 1 4
1 2 0
2 3 1
3 2 4 
4 0 3
</code></pre>

<p>Do you know how I could do to have the output I want? </p>