I have a list of hundreds of 2-tuples:
tuples = [('foo', 'bar'), ('hi', 'bar'), ('hi', 'bye'),
('dddd', 'cccc'), ('bbbb', 'cccc'), ('aaaa', 'xxxx') ... ]
My aim is to build clusters: every time an element appears in a tuple, it is similar to the elements of this tuple and to all the elements similar to the elements of this tuple. So I want it to be recursive.
With this example, "foo" is similar to "bar" and bar appears with "hi", so we add "hi", and then "hi" appears with "bye", so we add "bye", etc:
clusters = [('foo', 'bar', 'hi', 'bye'),
('dddd', 'cccc', 'bbbb'),
('aaaa', 'xxxx')]
Is there a good algorithm for that? Thanks!