Warning

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

networkx.classes.function.add_path

add_path(G_to_add_to, nodes_for_path, **attr)[source]

Add a path to the Graph G_to_add_to.

Parameters:
  • nodes_for_path (iterable container) – A container of nodes. A path will be constructed from the nodes (in order) and added to the graph.
  • attr (keyword arguments, optional (default= no attributes)) – Attributes to add to every edge in path.

Examples

>>> G = nx.Graph()
>>> nx.add_path(G, [0, 1, 2, 3])
>>> nx.add_path(G, [10, 11, 12], weight=7)