I am stuck on how to solve this problem.
Given a set of lists in a list, if any two sets of lists contain a common element, the two lists would be combined into one.
Suppose I have a set of lists in a list [[0, 1], [3, 6], [3, 9]]. Notice that [3, 6] and [3, 9] have a common element 3, so they are combined into [3, 6, 9], so how to convert this set of lists in a list into [[0,1], [3, 6, 9]]?
This is my current code but I am stuck.
for i in connected:
    for j in connected:
        a_set = set(i)
        b_set = set(j)
        if (a_set & b_set):
            i.extend(j)
            connected.remove(j)
    
 
     
    
 
    