2017-04-21 106 views
0

嘿傢伙即時嘗試從列表中刪除一些字符串使用另一個列表的內容。從列表中刪除字符串在另一個字符串列表

2個列表包含:

list a = ['help', 'python', 'spark', 'test', 'jupyter'] 
list b = ['help', 'python', 'spark'] 

現在我想從列表中刪除幫助蟒蛇和火花。

我想這:

newlist = [x for x in a if x not in b] 

但項目保留在列表中

+2

而問題是什麼? – user2722968

+0

從a和b前刪除'list' – depperm

+0

@depperm哦,這只是爲了顯示在這裏,我已經刪除了那個 –

回答

0

代替:

newlist = [x for x in a if x not in b] 

做:

a = [x for x in a if x not in b] 
相關問題