Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Digit Stack by TovarischZhukov
def digit_stack(commands):
stack = []
summ = 0
for comm in commands:
sp = comm.split(" ")
act= sp[0]
if len(sp)==2:
val= sp[1]
if act == "PUSH":
stack.append(int(val))
elif act =="PEEK":
summ += stack[-1] if stack else 0
elif act == "POP":
summ += stack.pop() if stack else 0;
return summ
Dec. 6, 2015