Log In
NP Code Competition

Close ALL the parentheses

Back to Problem Listing
Write a function called match_all that takes in a string which can be any arbitrary chunk of text. This text may have parentheses in them. Return True if all the parentheses are "well-formed". By "well-formed", I mean each opening parenthesis has a matching closing parenthesis, and no closing parenthesis occurs without a corresponding opening parenthesis before it.

Sample

>>> match_all("(meow)")
True
>>> match_all(")woof(")
False
>>> match_all("(1(2(3)4)5)")
True
>>> match_all("(1)(2(3)4(5))")
True
>>> match_all("(1)(2(3)4)5)(")
False
>>> match_all("(((((((((((())))))))))))")
True
This contest has ended. No more answers will be accepted.