Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
dict of a function solution in Clear category for Digit Stack by Olpag
def digit_stack(commands):
func = {'PUSH': lambda stack, arg: stack.append(arg),
'POP': lambda stack: stack.pop() if stack else 0,
'PEEK': lambda stack: stack[-1] if stack else 0}
stack, summ = [],0
for command in commands:
com, arg = '',''
if command.find('PUSH') != -1:
com, arg = command.split()
func[com](stack, arg)
else:
com = command
summ += int(func[com](stack))
return summ
April 3, 2019
Comments: