146k views
5 votes
"Write a function named remove_all that accepts" a string and a character as parameters, and removes all occurrences of the character. For example, the call of remove_all("Summer is here!", 'e') should return "Summr is hr!". Do not use the string replace function in your solution.

1 Answer

0 votes

Answer:

def remove_all(text, char):

return ''.join(x for x in text if x not in char )

print(remove_all("Summer is here!", 'e'))

Step-by-step explanation:

- join() method in Python takes all the element in the string and joins them. However, inside the join method, we excluded the elements that equals to char in the text

User Valerio Bozz
by
4.5k points