Balanced Parenthesis X22874


Statement
 

pdf   zip   main.py

thehtml

Write a function balanced(s) that given a string containing only open and closed parenthesis, returns True if the string contains well-formed parenthesis combination and False otherwise

Observation

Only the function is needed. If you have a test main program, embed it inside a block if __name__=="__main__" :

Sample session
>>> balanced('(())()()')
True
>>> balanced('(()()))(')
False
>>> balanced('())()')
False
>>> balanced('((()')
False
Information
Author
Lluís Padró
Language
English
Official solutions
Python
User solutions
Python