我想从两个列表中删除重复的值。预期的输入和输出如下所示:
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)
答案 0 :(得分:-1)
您可以基于切片进行过滤
l = list(filter(lambda x: x[:2] not in firstList, secondList))
# [['i-am3', 'banana', 'test ok']]