How to remove the letters from word1 if they exist in word2 with Python

1 Answer

0 votes
def remove_common_letters(word1, word2):
    return ''.join([char for char in word1 if char not in word2])

word1 = "forest"
word2 = "tor"

result = remove_common_letters(word1, word2)

print(result) 



'''
run:

fes

'''

 



answered Jul 8, 2025 by avibootz
edited Jul 8, 2025 by avibootz
...