从2个列表中删除重复值

时间:2018-10-08 07:54:28

标签: python list duplicates

我想从两个列表中删除重复的值。预期的输入和输出如下所示:

firstList = [['i-am1', 'apple'], ['i-am2', 'orange']]

secondList = [['i-am1', 'apple', 'asks'], ['i-am2', 'orange', 'last one'], ['i-am3', 'banana', 'test ok']]

result = [['i-am3', 'banana', 'test ok']]

我尝试使用set(),但是它不起作用。

sumfirstList = set(map(tuple, firstList))
sumsecondList = set(map(tuple, secondList))
result_all = set(sumfirstList) ^ set(sumsecondList)

1 个答案:

答案 0 :(得分:-1)

您可以基于切片进行过滤

l = list(filter(lambda x: x[:2] not in firstList, secondList))
# [['i-am3', 'banana', 'test ok']]