Python Write Function Removes Occurrences Given Letter String 1 2 3 4 5 6 Test Removelette Q37148601

IN PYTHON Write a function that removes all occurrences of agiven letter from a string: 1 2 3 4 5 6 test(remove_letter(“a”,”apple”) == “pple”) test(remove_letter(“a”, “banana”) == “bnn”)test(remove_letter(“z”, “banana”) == “banana”)test(remove_letter(“i”, “Mississippi”) == “Msssspp”)test(remove_letter(“b”, “”) = “”) test(remove_letter(“b”, “c”) =”c”) PYTHON PLEASE


Solution


def remove_letter(ch, string): res = ” for c in string: if c != ch: res += c return res

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.