如何删除列表中的重复项目。例如蜘蛛给我低于输出:
[
{"category": "Movies", "id": 4},
{"category": "Movies", "id": 5}
{"category": "Movies", "id": 4}
]
我想删除第一个和最后一个项目,因为它们是相同的。请帮忙。
答案 0 :(得分:0)
x将是您的清单
uniquex = []
deleted = []
for i in x:
if i in uniquex:
uniquex.remove(i)
deleted.append(i)
elif i not in deleted:
uniquex.append(i)