Balanced parentheses
Write balanced(text) that returns True if every ( in text is closed
by a later ) in the right order, and False otherwise. Only round
brackets count; every other character, including [ and {, is ignored.
balanced("(a + b) * (c)") -> True
balanced("(()") -> False
balanced("())(") -> False
balanced("") -> True
def balanced(text):
stack = []
for ch in text:
...
return ...