title: The distances between lists of vertices (not two vertices) in python
body: <p>I used previously the function <a href="https://igraph.org/r/doc/distances.html" rel="nofollow noreferrer">distance()</a> in igraph which computes the distance between two nodes or two vectors of nodes. Now I am writing a code in python using <a href="https://networkx.github.io/documentation/stable/index.html" rel="nofollow noreferrer">NetworkX 2.2</a> and I am trying to find also the distance between two lists of nodes <em>(not two nodes)</em>.</p>
  
  <p>It seems that there is no function can do this in NetworkX. In fact I used  <a href="https://networkx.github.io/documentation/stable/reference/algorithms/generated/networkx.algorithms.shortest_paths.generic.shortest_path_length.html#networkx.algorithms.shortest_paths.generic.shortest_path_length" rel="nofollow noreferrer">shortest_path_length()</a> but it didn't work. What I am doing here is : 1. read the graph edge by edge, 2. then for each edge to select the first vertex v1 and the second vertex v2, 3. find the neighbors connected to the first vertex and also find the connected neighbors to the second vertex, 4. finally compute the distance between the neighbors of v1 and neighbors of v2.</p>
  
  <p>At the end I want to get,for each edge, a vector contains the distances between the neighbors for both vertices v1 and v2. My code in R</p>
  
  <pre><code>library(igraph)
  graph&lt;-matrix(c(4,3,4,1,4,2,3,2,3,1),ncol=2,byrow=TRUE)
  g&lt;-graph.data.frame(d = graph, directed = FALSE)
  
  v1&lt;-c()
  v2&lt;-c()
  n1&lt;-list()
  n2&lt;-list()
  distance&lt;-list()
  distance.bt.neighbors&lt;-list()
  
  for(edge in 1:length(E(g))){
    v1[edge]&lt;-ends(graph = g, es = edge)[1]
    v2[edge]&lt;-ends(graph = g, es = edge)[2]
    n1&lt;-neighbors(g,v1[edge],mode=c("all"))
    n2&lt;-neighbors(g,v2[edge],mode=c("all"))
    distance[[edge]]&lt;-distances(g, v = n1, to = n2, mode = c("all"))
    distance.bt.neighbors[[edge]]&lt;-c(distance[[edge]])
                             }
  distance.bt.neighbors
  [[1]]
  [1] 1 1 1 1 0 2 1 2 0
  
  [[2]]
  [1] 1 1 1 0 1 1
  
  [[3]]
  [1] 1 1 1 0 1 1
  
  [[4]]
  [1] 0 1 1 1 1 1
  
  [[5]]
  [1] 0 1 1 1 1 1
  </code></pre>
  
  <p>To do this in python, I wrote this code</p>
  
  <pre><code>import os
  import igraph
  import numpy as np
  import networkx as nx
  
  os.chdir('Desktop')
  
  graph = nx.read_edgelist("attempt") # the file attempt contains the same data as in the R code.
  
  neighbor1 = []
  neighbor2 = []
  distance = []
  
  for edge in list(graph.edges):
    neighbor1.append(list(graph.neighbors(edge[0])))
    neighbor2.append(list(graph.neighbors(edge[1])))
    distance.append(nx.shortest_path_length(graph, source=neighbor1, target= neighbor2))
  </code></pre>
  
  <p>But I got this error which states that the neighbors are not defined as vertices since they are lists not single values</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 4, in &lt;module&gt;
  File "/home/abdelrahman/anaconda/lib/python3.7/site-packages/networkx/algorithms/shortest_paths/generic.py", line 312, in shortest_path_length
  p = nx.bidirectional_shortest_path(G, source, target)
  File "/home/abdelrahman/anaconda/lib/python3.7/site-packages/networkx/algorithms/shortest_paths/unweighted.py", line 223, in bidirectional_shortest_path
  raise nx.NodeNotFound(msg.format(source, target))
  networkx.exception.NodeNotFound: Either source [['3', '4']] or target [['1', '2']] is not in G
  </code></pre>
  
  <p>Is there a possibility in python to get a list for the distances between lists of of vertices, not single values, as  I did in R ? Is there such a function and if not is it possible to modify the current function?</p>
  
  <p>Note: I didn' use igraph-python to get the required list for two reasons: there is no such function , according to my search , in igraph and to stay away from the problem of loosing the names of vertices produced when tryinh to get neighbors for vertices.</p>