def join_clusters(clusters):
    idx = 0
while idx < len(clusters) - 1:
    for element in clusters[idx]:
        if element in clusters[idx + 1]:
            clusters[idx].remove(element)
clusters[idx] = clusters[idx] + clusters[idx + 1]
del clusters[idx + 1]
break
idx = idx + 1
return clusters
Merging sublists that contain common elements