Quote:
as I am writing its function it is not working. I can't figure out why.
I would start by simplifying the code to:
def remove_chars(word, char_list):
for char in word:
if char in char_list:
char = 'extra'
word= word.replace(char, '')
else:
char = char
return word
Then I would reverse the loop to:
def remove_chars(word, char_list):
for char in char_list:
word= word.replace(char, '')
return word
because not all languages can handle looping in a list while messing with it at same time.