Check brackets for balancing, using stack in python
<p>I'm solving such issue:
I need to implement a feature for a string to find errors in the usage of brackets.
If string is balanced, then I should return</p>

<pre><code>{}    
Success
</code></pre>

<p>If not, I need to mention the position of problematic bracket. </p>

<pre><code>{[}
3
</code></pre>

<p>So for that reason I decided to create a class Bracket</p>

<pre><code>class Bracket:
    def __init__(self, bracket_type, position):
        self.bracket_type = bracket_type
        self.position = position

    def Match(self, c):
        if self.bracket_type == '[' and c == ']':
            return True
        if self.bracket_type == '{' and c == '}':
            return True
        if self.bracket_type == '(' and c == ')':
            return True
        return False
</code></pre>

<p>Next, I'm using stack, whether sting is balanced or not. I created a loop, going through every symbol, and if symbol is a bracket I want to assign it to my special class in order to match for closing one further.</p>

<pre><code>if __name__ == "__main__":
    text = sys.stdin.read()

    brackets_stack = []
    Balanced = True


    for i, symbol in enumerate(str(text)):
        if symbol in ['(', '[', '{']:
            j = i
            brackets_stack.append(symbol)
            new_bracket = Bracket(brackets_stack[j], j)

        elif new_bracket.Match(symbol) == True:
            brackets_stack.pop(i)

        elif len(brackets_stack) == 0:
            print("Success")
</code></pre>

<p>But it works good only with cases like this </p>

<pre><code>{}    
Success
</code></pre>

<p>For other tests, like </p>

<pre><code>[()]
</code></pre>

<p>It shows that array is not empty yet, as his tenth is equal to 1. I think the problem lies in variable new_bracket. After removing "(" from array my program doesn't compare "{" for matching.</p>

<p>I don't know why.</p>

<p>Can somebody help me? </p>