Get all edges linked to a given node in a networkx graph
问题 Just wondering if there is convenient networkx function that returns a list of edges connected to a given node (or nodes) (e.g. my_node_name ) in a graph (e.g. G ). I can do it this way: edlist=[] for ed in G.edges(): if 'my_node_name' in ed: edlist.append(ed) but expect there might be a better way? 回答1: If the graph is undirected, you can use G.edges(node) In networkx 2.x this is an EdgeDataView object. In networkx 1.x this is a list - if you want a generator in 1.x rather than getting the