I have a list of lists and I want to group them according to at least one element in common for at least two sublists of a group. Therefore, each sublist in a specific group doesn't need to have an element in common with every sublist in its group, but it is enough that each sublist has at least one element in common with another sublist of its group - in other words, they can form a chain.
Example:
In: f(ls = [[3, 4, 2], [1, 3, 5], [9, 8, 7], [8, 10, 34], [34], [1], [23, 22, 21], [22], [21, 29], [100]])
Out:
{0: [[3, 4, 2], [1, 3, 5], [1]], 1: [[9, 8, 7], [8, 10, 34], [34]], 2: [[23, 22, 21], [22], [21, 29]], 3: [[100]]}
Who is f()
?
I'll keep trying to solve it for while.