PW Akshay

Generation

generate functionFri, 02 Dec 2022

Write a Python program to implement a stack using list.

def stack(): stack = [] return stack def push(stack, item): stack.append(item) def pop(stack): if len(stack) == 0: return None else: return stack.pop() def peek(stack): if len(stack) == 0: return None else: return stack[-1] stack = stack() push(stack,1) push(stack,2) push(stack,3) push(stack,4) print(pop(stack))

Questions about programming?Chat with your personal AI assistant