parse_multiline_adjlist

parse_multiline_adjlist(lines, comments='#', delimiter=None, create_using=None, nodetype=None, edgetype=None)[source]

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

Parameters
lineslist or iterator of strings

Input data in multiline adjlist format

create_usingNetworkX graph constructor, optional (default=nx.Graph)

Graph type to create. If graph instance, then cleared before populated.

nodetypePython type, optional

Convert nodes to this type.

edgetypePython type, optional

Convert edges to this type.

commentsstring, optional

Marker for comment lines

delimiterstring, optional

Separator for node labels. The default is whitespace.

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)
>>> list(G)
[1, 2, 3, 5]