Created
November 26, 2018 19:06
-
-
Save dbc2201/dda6ad13c91932e4054e612490421f8a to your computer and use it in GitHub Desktop.
to match parenthesis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def match(str1): | |
| str1 = str1.replace(" ", "") ## Omitting all the blank characters from the string | |
| index1 = str1.index("(") ## Checking if we have the string starts with opening bracket | |
| if index1 == 0: | |
| diff = str1.count("(") - str1.count(")") ## Checking the difference in bracket count | |
| if diff == 0: | |
| print("True") | |
| else: | |
| print("False") | |
| else: | |
| print("False") | |
| match(") ) ( (") | |
| match("( ( ) )") | |
| match("( ( )") | |
| match("( ( ) ( ) )") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment