algorizm to merge nodes

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Oct 17 17:17:58 EDT 2008


JD, you probably need the algorithm for connected components of an
undirected graph.

For example you can do that with my graph lib:
http://sourceforge.net/projects/pynetwork/

from graph import Graph
g = Graph()
data = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['a', 'g'], ['e', 'k'],
['c', 'u'], ['b', 'p']]
g.addArcs(data, bi=True)

print g.connectedComponents()
# Output: [['a', 'b', 'g', 'p'], ['c', 'u', 'd'], ['e', 'k', 'f']]

Bye,
bearophile



More information about the Python-list mailing list