s = "baabaa" stack = [] for i in range(len(s)): if stack and stack[-1] == s[i]: stack.pop() else: stack.append(s[i]) print(stack)
To embed this project on your website, copy the following code and paste it into your website's HTML: