Python Shortest path between 2 points
Question: I have found many algorithms and approaches that talk about finding the
shortest path between 2 points , but i have this situation where the data is
modeled as :

    
    
    [(A,B),(C,D),(B,C),(D,E)...] # list of possible paths
    

If we suppose i need the path from A to E , the result should be:

    
    
    (A,B)=>(B,C)=>(C,D)=>(D,E)
    

but i can't find a pythonic way to do this search.


Answer: The Pythonic way is to to use a module if one exists. As in this case, we
know, [networkx](http://networkx.github.io/) is there , we can write

**Implementation**

    
    
    import networkx as nx
    G = nx.Graph([('A','B'),('C','D'),('B','C'),('D','E')])
    path = nx.shortest_path(G, 'A', 'E')
    

**Output**

    
    
    zip(path, path[1:])
    [('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'E')]
    

