def is_valid_closer(string):
 openers = ['[', '(', '{']
 closers = [']', ')', '}']
 stack = []
 for ch in string:
  if ((not stack) and (ch in closers)):
   return False
  elif (ch in openers):
   stack.append(ch)
  elif (ch == ']'):
   if (stack.pop() != '['):
    return False
  elif (ch == ')'):
   if (stack.pop() != '('):
    return False
  elif (ch == '}'):
   if (stack.pop() != '{'):
    return False
 return (not stack)

def is_valid_closer ( string ) : openers = [ '[' , '(' , '{' ] closers = [ ']' , ')' , '}' ] stack = [ ] for ch in string : if ( ( not stack ) and ( ch in closers ) ) : return False elif ( ch in openers ) : stack . append ( ch ) elif ( ch == ']' ) : if ( stack . pop ( ) != '[' ) : return False elif ( ch == ')' ) : if ( stack . pop ( ) != '(' ) : return False elif ( ch == '}' ) : if ( stack . pop ( ) != '{' ) : return False return ( not stack )
returns true if every opener has a valid closer .