numbers = [1, 3, 5, 4, 0, 0, 7, 0, 0,0, 6] stack = [] for n in numbers: if n == 0: stack.pop() else: stack.append(n) print(sum(stack))
To embed this project on your website, copy the following code and paste it into your website's HTML: