Networkx - Shortest path length
import networkx as nx
G=nx.Graph()
G.add_nodes_from([1,2,3,4])
G.add_edge(1,2)
G.add_edge(3,4)
try:
n=nx.shortest_path_length(G,1,4)
print n
except nx.NetworkXNoPath:
print 'No path'
import networkx as nx
G=nx.Graph()
G.add_nodes_from([1,2,3,4])
G.add_edge(1,2)
G.add_edge(3,4)
try:
n=nx.shortest_path_length(G,1,4)
print n
except nx.NetworkXNoPath:
print 'No path'