python removing a string from another string using lists?

Viewed 82

I need my code to take 2 inputs, a string and a second string. In other words the first string is a sentence of some sort and the second string is just a few letters to be removed from the entire sentence. Example:

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

So far I have:

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)
1 Answers

You can use the replace function for this.

def remove(word, reword):
    return word.replace(reword, '')

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