I assume that you know your paths in advance. If you really start with a graph and want to โbreakโ it into tracks, let me know. Then I would suggest a different approach.
So I would come up with, maybe not the fastest or most elegant way, but it should work:
import networkx as nx
graph = nx.MultiGraph()
paths = [[1,2,3,4,5], [2,6,7], [4,8,9,10,11]]
for path in paths:
graph.add_path(path)
splitted_paths = []
splitting_nodes = [node for node in graph if graph.degree(node)>=3]
for path in paths:
splitting_nodes_in_path = [node for node in splitting_nodes if node in path]
for splitting_node in splitting_nodes_in_path:
path_piece = path[:path.index(splitting_node)+1]
if len(path_piece) > 1:
splitted_paths.append(path_piece)
path = path[path.index(splitting_node):]
if len(path) > 1:
splitted_paths.append(path)
print splitted_paths
Hope this helps!
EDIT 1: removed an unnecessary loop and added some missing lines of code
2: , @marcus, , "", a node >= 3, . , , , , , :
cut(graph, node), Networkx node (node) , node ( , , , )cut() >= 3 ,
, Networkx: remove_node(), subgraph(). all_simple_paths(), predecessor() Operators.