I need to define a function called remove_letters(str1,str2) which returns a string obtained by removing from string two every letter occurring in str1
So far I have this but It doesn't remove the duplicate letters, it only removes what you put in for it to remove.
def remove_letters(str1,str2):
str2_list = list(str2)
for char in str2:
str2_list.remove()
return (str2)
Update
I now need to test this function for a variety for strings. When called the code only returns the last result and not the first two. This is my code.
def test_remove_letters():
string_list = [('sop', 'sen'),('dog', 'god'),('lighter', 'darker')]
for str1,str2 in string_list:
print('The original words are', str1, 'and', str2)
return ('The result is', remove_letters(str1,str2))
Or in a loop:
Both the loop and the list comprehension have the same logic, we keep the chars in str2 that don't appear in str1.
Using your own code, you need to iterate over str2 and remove any char from str2_list that is in str1 then use join on the list to get a string: