一般讲list转化成set是最简单的方式,但是set是无序的,如果我们既希望保留list的顺序,又希望用到list的便捷,
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)