algorizm to merge nodes

bearophileHUGS at bearophileHUGS at
Sat Oct 18 05:01:41 CEST 2008

> 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']]


More information about the Python-list mailing list