Grouping pairs - suggested tools
arnodel at gmail.com
Tue Sep 21 10:51:38 CEST 2010
On Sep 20, 10:42 pm, Astley Le Jasper <astley.lejas... at gmail.com>
> I have a list of tuples that indicate a relationship, ie a is related
> to b, b is related to c etc etc. What I want to do is cluster these
> relationships into groups. An item will only be associated with a
> single cluster.
> Before I started, I wondered if there was any particular tool within
> Python I should be looking at. I don't expect anyone to code this for
> me, just say ... "you need to look at using x". I was going to use
> populate a dictionary and
> Sorry for being so vague.
> Example Data:
> Output (grouping id, item ref)
What you are doing is finding the connected components of a graph.
There aren't any tools in the standard library to do this. But for
example python-graph  has a connected_components function.
Probably other packages will. If you don't want a dependency, it is
not too hard to implement if you think about it.
More information about the Python-list