human
Reduce string by removing outermost parenthesis from each primitive substring | Function to remove the outermost parentheses of every primitive substring from the given string.
Stores the resultant string.
Stores the count of opened parentheses.
Traverse the string.
If opening parenthesis is encountered and their count exceeds 0.
Include the character.
If closing parenthesis is encountered and their count is less than count of opening parentheses.
Include the character.
Return the resultant string.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to reduce string by removing outermost parenthesis from each primitive substring and the other steps required.
 def removeOuterParentheses ( S ) :
	res = " "
	count = 0
	for c in S :
		if ( c == ' ( ' and count > 0 ) :
			res += c
		if ( c == ' ( ' ) :
			count += 1
		if ( c == ' ) ' and count > 1 ) :
			res += c
		if ( c == ' ) ' ) :
		count -= 1
	return res
if __name__ == ' _ _ main _ _ ' :
	S = " ( ( ) ( ) ) ( ( ) ) ( ) "
	print ( removeOuterParentheses ( S ) )