python使用列表从另一个字符串中删除字符串?

2024-10-02 20:41:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要我的代码接受2个输入,一个字符串和第二个字符串。换句话说,第一个字符串是某种类型的句子,第二个字符串只是从整个句子中删除的几个字母。例如:

remove("This is as it is.", "is") == 'Th  as it .'

到目前为止,我已经:

def remove(word, reword):
    s = set(reword)
    return (x for x in word if x not in s)

remove("This is as it is.", "is")
print(word)

Tags: 字符串代码in类型isdefas字母