简体   繁体   中英

remove duplicates some value from 2 lists

I want to remove duplicate values from the two list. The expected input and output are shown below:

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']]

I tried using set() and it doesn't not work.

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

You could filter based on slice

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM