Write a user define function in Python for push(list) and pop(list) for
performing push and pop operations with a stack of list containing integers.
Answers
Answered by
12
def push(item, stack):
stack += [item]
return stack
def pop(stack):
if stack:
item = stack[-1]
stack.remove(item)
return item
stack = [n for n in range(1, 11)]
for x in range(10, 21):
push(x, stack)
for _ in range(len(stack)):
print(pop(stack))
Similar questions