I have two dictionary objects, connections and network. This can be visualized as a graph, where each node is a computer and connections depict an edge between the computers and node. Network is a dictionary objects of unique networks where the computers can be a part, for ex
1,2
2,3
4,5
5,1
are four connection information for nodes 1 through 1
connections would thus be {1->1,2->1,3->1,4->2,5->1}
and network {1->0,2->1}
which means
computer 1,2,3,5 are part of n/w 1
computer 4 is part of n/w 2
again n/w 2 is interconnected to n/w 1
I have to read a file with thousand of such connection information
while doing so, for each connection info read I have to perform a non-sequential loop as follows
while network.has_key(connections[node1]):
connections[node1]=network[connections[node1]]
Is there a better way to optimize the above loop? If required I can share my entire code for the purpose