list deduplication, difference sets, the sequence remains unchanged

Generally speaking converted into the set list is the easiest way, but the set is out of order, if we both want to keep the order list, but want to use the list of convenient,

l1 = [1,2,3,4,8,9,6,2]
l2 = [ 2,6,9]
differ = set(l1)-set(l2)
differ.sort(key=l1.index)
print(differ)

 

Guess you like

Origin www.cnblogs.com/dolphin-bamboo/p/11298365.html