algorizm to merge nodes
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Fri Oct 17 23:01:41 EDT 2008
JD:
> Thanks,
> This one really works.
Note that you can save some RAM (almost half) creating a directed
graph, because later the connectedComponents() manages the arcs as
undirected anyway:
>>> from graph import Graph
>>> g = Graph()
>>> data = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['a', 'g'], ['e', 'k'], ['c', 'u'], ['b', 'p']]
>>> g.addArcs(data)
>>> g.connectedComponents()
[['a', 'b', 'g', 'p'], ['c', 'u', 'd'], ['e', 'k', 'f']]
Bye,
bearophile
More information about the Python-list
mailing list