Python: Validity of a string of parentheses
3. Check Validity of a String of Parentheses
Write a Python class to check the validity of a string of parentheses, '(', ')', '{', '}', '[' and ']. These brackets must be closed in the correct order,
for example "()" and "()[]{}" are valid but "[)", "({[)]" and "{{{" are invalid.
Sample Solution:
Python Code:
Sample Output:
True False True
Pictorial Presentation:
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python class that uses a stack to verify if a string containing '()', '{}', and '[]' is balanced and valid.
- Write a Python class that implements recursive descent parsing to check the validity of nested parentheses in a string.
- Write a Python class that uses a dictionary to match opening and closing brackets and determines the string's validity.
- Write a Python class that handles edge cases (empty string, single bracket) and returns a boolean indicating whether the parentheses are correctly balanced.
Go to:
Previous: Write a Python class to convert a roman numeral to an integer.
Next: Write a Python class to get all possible unique subsets from a set of distinct integers.
Python Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.