Created
September 3, 2020 16:01
-
-
Save ynonp/dba3900180e72ce8ff0369c770f0219b to your computer and use it in GitHub Desktop.
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
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