Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created September 3, 2020 16:01
Show Gist options
  • Save ynonp/dba3900180e72ce8ff0369c770f0219b to your computer and use it in GitHub Desktop.
Save ynonp/dba3900180e72ce8ff0369c770f0219b to your computer and use it in GitHub Desktop.
text = "some string (with parentheses (and also inner parentheses)) (yay) hi"
stack = []
for i in range(len(text)):
char = text[i]
if char == "(":
stack.append(char)
elif char == ")":
stack.pop()
if len(stack) == 0:
print("REPLACED", end="")
elif len(stack) == 0:
print(char, end="")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment