Here is a solution working with sets:
It works with OP example and also example given in the comments.
a = [[1,2], [2,3],[7,9]]
b = [[2,4], [6,7]]
a = a+b
b = []
while a != []:
i = a.pop()
for j in range(len(b)):
if set(b[j]).intersection(set(i)) != set():
b[j] = list(set(b[j]).union(set(i)))
break
else:
if i != []:
b.append(i)
print(b)
## [[9, 6, 7], [1, 2, 3, 4]]
Other tests:
a = [[8, 9], [1,2],[5,3],[7,9], [5, 6]]
b = [[2,4], [6,7]]
## [[3, 5, 6, 7, 8, 9], [1, 2, 4]]
a = [[1,2], [2,3],[7,9]]
b = [[2,4], [6,7]]
## [[9, 6, 7], [1, 2, 3, 4]]