Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

parse_adjlist

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

Parse lines of a graph adjacency list representation.

Parameters :

lines : list or iterator of strings

Input data in 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. The default is whitespace.

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 adjacency list format.

See also

read_adjlist

Examples

>>> lines = ['1 2 5',
...          '2 3 4',
...          '3 5',
...          '4',
...          '5']
>>> G = nx.parse_adjlist(lines, nodetype = int)
>>> G.nodes()
[1, 2, 3, 4, 5]
>>> G.edges()
[(1, 2), (1, 5), (2, 3), (2, 4), (3, 5)]