我試圖找出所有在列表A和不在列表B.Python列表差異
我覺得像newList = list(set(a) & !set(b))
或newList = list(set(a) & (not set(b)))
東西會工作的元素,但它不是。
如果還有更好的方法來實現我想要做的除此之外的事情嗎?
newList = []
for item in a:
if item not in b:
newList.append(item)
同樣重要的,它需要在Python 2.6
請注意,從列表 - >設置 - >列表的轉換將失去原始列表的排序。 – sirdodger 2012-07-20 21:02:12