NetworkX: How to find the source and target nodes of a directed edge
Question: dito above.. I couldn't find anything in the NetworkX docs...

In Python Igraph, i can just use:

    
    
    import igraph as ig
    G = ig.Graph(directed=True)
    G.add_vertices(2)
    G.add_edge(0,1)
    eid = G.get_eid(0,1)
    edge = G.es[eid]
    nodes = (edge.source, edge.target)
    print nodes
    


Answer: The ordering of the tuples is significant. The first element is the source and
the second is the target.

    
    
    In [1]: import networkx as nx
    
    In [2]: G = nx.DiGraph()
    
    In [3]: G.add_edge(1,2) # 1->2
    
    In [4]: G.add_edge(2,3) # 2->3
    
    In [5]: list(G.edges())
    Out[5]: [(1, 2), (2, 3)] # 1->2 and 2->3
    
    In [6]: G.add_edge(42,17) # 42->17
    
    In [7]: list(G.edges())
    Out[7]: [(1, 2), (2, 3), (42, 17)]
    
    In [8]: for e in G.edges():
       ...:     source,target = e
       ...:     print source
       ...:     
    1
    2
    42
    

