Merge lists that share common elements
You can see your list as a notation for a Graph, ie [‘a’,’b’,’c’] is a graph with 3 nodes connected to each other. The problem you are trying to solve is finding connected components in this graph. You can use NetworkX for this, which has the advantage that it’s pretty much guaranteed to be correct: … Read more