All MicroEvals
Write a python function to remove first and last occurrence ...
Create MicroEval
Header image for Write a python function to remove first and last occurrence ...

Write a python function to remove first and last occurrence ...

Prompt

Write a python function to remove first and last occurrence of a given character from the string. Your function should satisfy these tests: ```python assert remove_Occ("hello","l") == "heo" assert remove_Occ("abcda","a") == "bcd" assert remove_Occ("PHP","P") == "H" ```

Answer guidance

Reference solution: def remove_Occ(s,ch): for i in range(len(s)): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break for i in range(len(s) - 1,-1,-1): if (s[i] == ch): s = s[0 : i] + s[i + 1:] break return s

Drag to resize
Drag to resize
Drag to resize