如果我有这样的清单:
examList = [1,1,2,2,3,4,5,6]
如何从列表中删除任何重复项,只返回唯一值以获取以下列表:
resultList =[3,4,5,6] # [1,2] were deleted because they appeared more than once.
基本上不仅删除重复的事件,而且删除重复的数字本身。我知道你可以使用
set(examList)
或
is in
但是那些不会删除重复数字,一般只删除重复的数字。
答案 0 :(得分:-1)
尝试这样的列表理解:
result = [item for item in examList if examList.count(itemm) == 1]