I need to get the tuple positions which are linked to each other with at least one element within it.
[('1','1','1'),
('X','1','X'),
('Z','Z','Z'),
('Y','Y','X')]
Here, in 1st tuple value '1' present in 2nd tuple. And, now in 2nd tuple value 'X' present in last tuple.
So, I need to combine all these into one list whereas tuple 3 values['Z'] are not matching with any other tuples. So, it is stored in separate list.
Expected : [[0,1,3],[2]]
My approach:
df = [('1','1','1'),('X','1','X'),('Z','Z','Z'),('Y','Y','X')]
res = [list(sub) for sub in df]
res
count=0
list_A=[]
for i,j in enumerate(res):
for m,n in enumerate(j):
if res[i][m] in res[i]:
print(res.index(j))