2012-02-21 13 views

Odpowiedz

9

networkx.simple_cycles robi to za Ciebie.

>>> import networkx as nx 
>>> G = nx.DiGraph() 
>>> G.add_edge('A', 'B') 
>>> G.add_edge('B', 'C') 
>>> G.add_edge('C', 'D') 
>>> G.add_edge('C', 'A') 
>>> nx.simple_cycles(G) 
[['A', 'B', 'C', 'A']]