human
Remove the first and last occurrence of a given Character from a String | Function to remove first and last occurrence of a given character from the given string.
Traverse the given string from the beginning.
If ch is found.
Traverse the given string from the end.
If ch is found.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to remove the first and last occurrence of a given Character from a String and the other steps required.
 def removeOcc ( 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
s = " hello ▁ world "
ch = ' l '
print ( removeOcc ( s , ch ) )