Skip to main content
 首页 » 编程设计

python之如何过滤掉python中的单词

2025年05月04日14qq78292959

<分区>

例如:

item =['the dog is gone', 'the dog and cat is gone'] 
words= ['dog','cat']  

我希望能够过滤掉 dog 和 cat 所以它会显示为:

item=['the  is gone', 'the   and  is gone'] 

item1=[]  
for w in words: 
   for line in item: 
      if w in line: 
         j=gg.replace(it,'') 
         item1.append(j) 

我得到以下信息:

['the  is gone', 'the cat and  is gone', 'the  and dog is gone']