human
Reverse substrings between each pair of parenthesis | Function to return the modified string.
Push the index of the current opening bracket.
Reverse the substarting after the last encountered opening bracket till the current character.
To store the modified string.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to reverse substrings between each pair of parenthesis and the other steps required.
 def reverseParentheses ( strr , lenn ) :
	st = [ ]
	for i in range ( lenn ) :
		if ( strr [ i ] == ' ( ' ) :
			st . append ( i )
		elif ( strr [ i ] == ' ) ' ) :
			temp = strr [ st [ - 1 ] : i + 1 ]
			strr = strr [ : st [ - 1 ] ] + temp [ : : - 1 ] + strr [ i + 1 : ]
			del st [ - 1 ]
	res = " "
	for i in range ( lenn ) :
		if ( strr [ i ] != ' ) ' and strr [ i ] != ' ( ' ) :
			res += ( strr [ i ] )
	return res
if __name__ == ' _ _ main _ _ ' :
	strr = " ( skeeg ( for ) skeeg ) "
	lenn = len ( strr )
	st = [ i for i in strr ]
	print ( reverseParentheses ( strr , lenn ) )