Parse lines of an edge list representation of a graph.
Returns : | G: NetworkX Graph :
data : bool or list of (label,type) tuples
create_using: NetworkX graph container, optional :
nodetype : Python type, optional
comments : string, optional
delimiter : string, optional
create_using: NetworkX graph container :
|
---|
See also
Examples
Edgelist with no data:
>>> lines = ["1 2",
... "2 3",
... "3 4"]
>>> G = nx.parse_edgelist(lines, nodetype = int)
>>> G.nodes()
[1, 2, 3, 4]
>>> G.edges()
[(1, 2), (2, 3), (3, 4)]
Edgelist with data in Python dictionary representation:
>>> lines = ["1 2 {'weight':3}",
... "2 3 {'weight':27}",
... "3 4 {'weight':3.0}"]
>>> G = nx.parse_edgelist(lines, nodetype = int)
>>> G.nodes()
[1, 2, 3, 4]
>>> G.edges(data = True)
[(1, 2, {'weight': 3}), (2, 3, {'weight': 27}), (3, 4, {'weight': 3.0})]
Edgelist with data in a list:
>>> lines = ["1 2 3",
... "2 3 27",
... "3 4 3.0"]
>>> G = nx.parse_edgelist(lines, nodetype = int, data=(('weight',float),))
>>> G.nodes()
[1, 2, 3, 4]
>>> G.edges(data = True)
[(1, 2, {'weight': 3.0}), (2, 3, {'weight': 27.0}), (3, 4, {'weight': 3.0})]