Skip to content

Instantly share code, notes, and snippets.

@dbc2201
Created November 26, 2018 19:06
Show Gist options
  • Select an option

  • Save dbc2201/dda6ad13c91932e4054e612490421f8a to your computer and use it in GitHub Desktop.

Select an option

Save dbc2201/dda6ad13c91932e4054e612490421f8a to your computer and use it in GitHub Desktop.
to match parenthesis
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