def add_nodes_from(graph, node_list):
"""Add nodes from a node list.
Parameters
----------
graph : networkx.(Di)Graph
node_list : iterable
Iterable containing a collection of nodes, optionally,
with their attributes
Examples
--------
>>> import networkx as nx
>>> from regraph.primitives import add_nodes_from
>>> G = nx.Graph()
>>> add_nodes_from(G, [1, (2, {"a": 1}), 3])
"""
for n in node_list:
try:
node_id, node_attrs = n
add_node(graph, node_id, node_attrs)
except (TypeError, ValueError) as e:
add_node(graph, n)
评论列表
文章目录