This documents the development version of NetworkX. Documentation for the current release can be found here.


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.

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.

G: NetworkX graph

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


>>> 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]