let's say i have a list , list=[[0,1,2],[1,2,0],[2,1,3],[3,1,2]]. i want to match and group the arrays position in the list which has same numbers in spite of their position and get their indices. for example my code should give [0,1,2] and [1,2,0] are same and their position is 0 and 1. I need a code to group all the elements in the list like this. I know a basic way of doing this with for and if loop but i want to know is there a efficient way to do this in python.
Edit- I implemented the solution using below code, it is doing what i want to do. I want to know is there a efficient way to do this.
import numpy as np
pairs=[[0,1],[1,0],[1,2],[2,1]]
for j in range(4):
pairs[j]=sorted(pairs[j])
print(pairs)
pr=(len(pairs))
unique=np.unique(pairs,axis=0)
print(unique)
house_clusters=list()
for t in range(len(unique)):
uni=unique[t]
seq2=list()
for r in range (pr):
if np.array_equal(pairs[r],uni):
seq2.append(r)
house_clusters.append(seq2)
print(house_clusters)