Finding all paths/walks of given length in a networkx graph
Simplest version (another version is below which I think is faster): def findPaths(G,u,n): if n==0: return [[u]] paths = [[u]+path for neighbor in G.neighbors(u) for path in findPaths(G,neighbor,n-1) if u not in path] return paths This takes a network G and a node u and a length n. It recursively finds all paths of length … Read more