Delete duplicate tuples with same elements in nested list Python

巧了我就是萌 提交于 2019-12-06 00:04:06

In this solution, I am copying each of the tuples into a temp after checking whether it is already present in the temp and then copy 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 output as expected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!