我有一个名为'abc'的列表(字符串),我正在尝试从列表'stop'中删除一些单词,并从列表'abc'中删除所有数字。
abc=[ 'issues in performance 421',
'how are you doing',
'hey my name is abc, 143 what is your name',
'attention pleased',
'compliance installed 234']
stop=['attention', 'installed']
我正在使用列表推导式来删除它,但是下面的代码无法删除那个单词。
new_word=[word for word in abc if word not in stop ]
结果:(注意词汇仍然存在。)
['issues in performance',
'how are you doing',
'hey my name is abc, what is your name',
'attention pleased',
'compliance installed']
期望输出:
['issues in performance',
'how are you doing',
'hey my name is abc, what is your name',
'pleased',
'compliance']
谢谢
word
不是一个单词,而是一个句子。 - Ankit Jaiswal