Popular recipes tagged "connection"http://code.activestate.com/recipes/tags/connection/2012-04-24T18:47:21-07:00ActiveState Code RecipesFinding complete loops in a map of connected nodes (Python)
2012-04-24T18:47:21-07:00Sachin Joglekarhttp://code.activestate.com/recipes/users/4181845/http://code.activestate.com/recipes/578110-finding-complete-loops-in-a-map-of-connected-nodes/
<p style="color: grey">
Python
recipe 578110
by <a href="/recipes/users/4181845/">Sachin Joglekar</a>
(<a href="/recipes/tags/circuit/">circuit</a>, <a href="/recipes/tags/connection/">connection</a>, <a href="/recipes/tags/loops/">loops</a>).
</p>
<p>This module finds loops in a given map.Input is a dictionary like</p>
<p>d={1:[2,4,5,6],2:[1,3],3:[2,4,5,6],4:[1,3,5],5:[1,3,4],6:[1,3]}</p>
<p>this means node 1 is connected to nodes 2,4,5 and 6 and so on..</p>
<p>Output is a list of complete loops.
for above examples,output is</p>
<p>[[1, 4, 5, 1], [3, 4, 5, 3], [1, 2, 3, 4, 1], [1, 2, 3, 5, 1], [1, 2, 3, 6, 1], [1, 4, 3, 5, 1], [1, 4, 3, 6, 1], [1, 5, 3, 6, 1], [1, 2, 3, 4, 5, 1], [1, 4, 5, 3, 6, 1]]</p>