I have been trying to remove duplicate arrays in my array list (ie. [[2,1],[1,2]) I want to get rid of only one of the arrays. I tried to reverse the list to and remove the duplicates but that does not work.
def grf_to_edge_list(file):
edgelist = []
for line in file:
y = line.split()
for i in range(3,len(y)):
edgelist.append([int(y[0]),int(y[i])])
for i in range(len(edgelist)-1):
temp = edgelist[i]
temp.reverse()
if temp in edgelist:
edgelist.remove(temp)
i = i - 1
return edgelist
Here is the exact data:
1 2.0 1.0 2 3
2 1.0 0.0 1 3
3 0.0 2.0 1 2 4
4 3.0 3.0 3
5 3.0 0.0
[1, 2]is not the same as[2, 1], but if you don't care about order and just want unique sets, you could just create sets instead of lists and put the sets in a set to remove duplicates among them.[0]and the numbers after the third one as[1]. This should have been explained in the question as well. The less we have to work to figure it out, the better your chances of getting answers.