NetworkX

Previous topic

networkx.readwrite.multiline_adjlist.write_multiline_adjlist

Next topic

networkx.readwrite.multiline_adjlist.generate_multiline_adjlist

networkx.readwrite.multiline_adjlist.parse_multiline_adjlist

networkx.readwrite.multiline_adjlist.parse_multiline_adjlist(lines, comments='#', delimiter=' ', create_using=None, nodetype=None, edgetype=None)

Parse lines of a multiline adjacency list representation of a graph.

Parameters :

lines : list or iterator of strings

Input data in multiline adjlist format

create_using: NetworkX graph container :

Use given NetworkX graph for holding nodes or edges.

nodetype : Python type, optional

Convert nodes to this type.

comments : string, optional

Marker for comment lines

delimiter : string, optional

Separator for node labels

create_using: NetworkX graph container :

Use given NetworkX graph for holding nodes or edges.

Returns :

G: NetworkX graph :

The graph corresponding to the lines in multiline adjacency list format.

Examples

>>> lines = ['1 2',
...          "2 {'weight':3, 'name': 'Frodo'}",
...          "3 {}",
...          "2 1",
...          "5 {'weight':6, 'name': 'Saruman'}"]
>>> G = nx.parse_multiline_adjlist(iter(lines), nodetype = int)
>>> G.nodes()
[1, 2, 3, 5]
>>> G.edges(data = True)
[(1, 2, {'name': 'Frodo', 'weight': 3}), (1, 3, {}), (2, 5, {'name': 'Saruman', 'weight': 6})]