小编use*_*878的帖子

如何过滤掉python中的单词?

例如:

item =['the dog is gone', 'the dog and cat is gone']
words= ['dog','cat'] 
Run Code Online (Sandbox Code Playgroud)

我希望能够过滤掉它dog,cat所以它会读取:

item=['the  is gone', 'the   and  is gone']
Run Code Online (Sandbox Code Playgroud)

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

我得到以下内容:

['the  is gone', 'the cat and  is gone', 'the  and dog is gone']
Run Code Online (Sandbox Code Playgroud)

python sorting string

1
推荐指数
1
解决办法
8437
查看次数

标签 统计

python ×1

sorting ×1

string ×1