result = [set(T[0])]
for sublst in islice(T, 1, len(T)):
    subset = set(sublst)
if result[idx] & subset:
    result[idx].update(subset)
else:
    result.append(set(sublst))
idx += 1
return [sorted(sub) for sub in result]
Merging sublists that contain common elements