With one kind of bracket a counter does instead of a stack: up on an opener, down on a closer. With two kinds counters are fooled: ([)] has one opener and one closer of each kind, the numbers agree, and the order is wrong. A stack remembers not only how many there are but in what order they were opened.
depth = 0for ch in text:depth += 1 if ch == "(" else -1if depth < 0:return Falsereturn depth == 0
")(" balanced.Remember too that a stack turns the order round: put in 1, 2, 3 and you take out 3, 2, 1. To reverse something, filling a stack and emptying it is enough; if you want to keep the order, a stack is the wrong tool.