You basically want to find connected components. For that there is a function connected_components in scipy. You just have to reinterpret your data a bit:
l = [(1,2), (2,3), (3,1), (4,5), (5,4), (6,7)]
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
# make list of unique elements
uniques = list(set(list(map(lambda a: a[0], l)) + list(map(lambda a: a[1], l))))
# reverse index to lookup elements index
unique2index = dict([(el, i) for (i, el) in enumerate(uniques)])
# prepare data for csr_matrix construction
data = [1 for x in l] # value 1 -- means edge
data_i = [unique2index.get(x[0]) for x in l] # source node
data_j = [unique2index.get(x[1]) for x in l] # target node
graphMatrix = csr_matrix((data, (data_i, data_j)),shape=(len(uniques), len(uniques)))
(numComponents, labels) = connected_components(graphMatrix) # here is the work done
# interpret labels back to original elements
components = [[uniques[j] for (j,x) in enumerate(labels) if x==i] for i in range(0, numComponents)]
print(components) # [[1, 2, 3], [4, 5], [6, 7]] is printed