fork(2) download
  1. BRACES = { '(': ')', '[': ']', '{': '}' }
  2.  
  3. def group_check(s):
  4. stack = []
  5. for b in s:
  6. c = BRACES.get(b)
  7. print("inside loop. stack: %s, b: %s" % (str(stack), b))
  8. print("not stack: %s" % str(not stack))
  9. if c:
  10. stack.append(c)
  11. elif not stack or stack.pop() != b:
  12. return False
  13. print("before return. stack: %s" % str(stack))
  14. return not stack
  15.  
  16.  
  17.  
  18. # print(group_check("()"))
  19. # print(group_check("({"))
  20. print(group_check("({}{}[])"))
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
inside loop. stack: [], b: (
not stack: True
inside loop. stack: [')'], b: {
not stack: False
inside loop. stack: [')', '}'], b: }
not stack: False
inside loop. stack: [')'], b: {
not stack: False
inside loop. stack: [')', '}'], b: }
not stack: False
inside loop. stack: [')'], b: [
not stack: False
inside loop. stack: [')', ']'], b: ]
not stack: False
inside loop. stack: [')'], b: )
not stack: False
before return. stack: []
True