Warning

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

networkx.readwrite.multiline_adjlist.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:
  • lines (list or iterator of strings) – Input data in multiline adjlist format
  • create_using (NetworkX graph constructor, optional (default=nx.Graph)) – Graph type to create. If graph instance, then cleared before populated.
  • 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.
Returns:

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

Return type:

NetworkX graph

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]