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