Skip to content

Finding a list of nodes in a range #7431

Answered by dschult
Quasarrs asked this question in Q&A
Discussion options

You must be logged in to vote

That looks like a very strange criteria. Maybe I am not understanding. Does the phrase "range between node "h" and "fd" mean some sort of alphabetic "between" or are you talking about something like "lie on a shortest path in the network between"?

But in general, if you have a criteria for including the nodes that can be written as an expression or a function, you can filter the list of nodes. Or you can create a subgraph and make a copy of that subgraph so it is it's own graph.

node_filter = lambda n : <some expression that returns True/False>
nodes = [n for n in G if node_filter(n)]  # list of nodes
SG = G.subgraph(nodes)
SG = G.subgraph(nodes).copy()  # this is usually how you want to …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rossbar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants