我正在尝试使用另一个列表作为参考从列表中的项目中删除特定字符。目前我有:
forbiddenList = ["a", "i"]
tempList = ["this", "is", "a", "test"]
sentenceList = [s.replace(items.forbiddenList, '') for s in tempList]
print(sentenceList)
我希望能打印出来:
["ths", "s", "test"]
当然,禁止列表非常小,我可以单独替换每个,但是当我有大量“禁止”项目时,我想知道如何“正确”执行此操作。