algorizm to merge nodes

JD Jiandong.Ge at gmail.com
Fri Oct 17 17:45:15 EDT 2008


Thanks,

This one really works.

JD

On Oct 17, 3:17 pm, bearophileH... at lycos.com wrote:
> 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