I want to find out if there are any circular connections using Python.
Let’s say I have a matrix A:
A = [["a", "b", "ab"], ["b", "d", "bd"], ["d", "c", "dc"], ["d", "a", "da"], ....]
In case of circular connection it prints the matrix T.
in this case:
T = [["a", "b", "ab", "b", "d", "bd", "d", "a", "da"],...]
I tried for loop inside for loop but I get weird results.
M = [["a", "b", "ab"], ["b","d","bd"], ["c","d","cd"], ["d", "a", "da"]] X = [] T = []
for i in M: if X != 0: X = i for j in M: if j[0] ==X[0] or j[0] == X[1] or j[1] ==X[0] or j[1] == X[1]: T.append(j) print(T)
Can anyone please help here? I am just a beginner at Python and would really apreciate any help.
Naser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1