title: How to choose paths that the compute average path length is one, or two in networkx?
body: <p>How to compute paths that the average path length is one, or two in networkx?
  For example, in this graph below, the average path length equals one is 6, and two is 2.</p>
  
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  G=nx.DiGraph()
  G.add_edges_from([(1, 2), (1, 5), (1, 6), (1, 9), (2, 3), (2, 4), (6, 7)])
  pos=nx.spring_layout(G, iterations=5000) 
  plt.figure()
  nx.draw(G, pos)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7UxK2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7UxK2.png" alt="enter image description here"></a></p>