(check_string)
| 30 | |
| 31 | |
| 32 | def is_balanced(check_string): |
| 33 | s = Stack() |
| 34 | index = 0 |
| 35 | is_bal = True |
| 36 | while index < len(check_string) and is_bal: |
| 37 | paren = check_string[index] |
| 38 | if paren in "{[(": |
| 39 | s.push(paren) |
| 40 | else: |
| 41 | if s.is_empty(): |
| 42 | is_bal = False |
| 43 | else: |
| 44 | top = s.pop() |
| 45 | if not is_same(top, paren): |
| 46 | is_bal = False |
| 47 | index += 1 |
| 48 | |
| 49 | if s.is_empty() and is_bal: |
| 50 | return True |
| 51 | else: |
| 52 | return False |
| 53 | |
| 54 | |
| 55 | print(is_balanced("[((())})]")) |