Remove duplicate tuples with same elements in python nested list
1 answer
In this solution, I copy each of the tuples in temp
after checking if it is present in temp
, and then copy it back to d
.
d = [(1,0),(2,3),(3,2),(0,1)]
temp = []
for a,b in d :
if (a,b) not in temp and (b,a) not in temp: #to check for the duplicate tuples
temp.append((a,b))
d = temp * 1 #copy temp to d
This will give the result as expected.
+3
source to share