def remove_node(graph, node_id):
"""Remove node.
Parameters
----------
graph : networkx.(Di)Graph
node_id : hashable, node to remove.
Raises
------
GraphError
If a node with the specified id does not exist.
"""
if node_id in graph.nodes():
neighbors = set(graph.__getitem__(node_id).keys())
neighbors -= {node_id}
graph.remove_node(node_id)
else:
raise GraphError("Node %s does not exist!" % str(node_id))
return
评论列表
文章目录