Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

implement stack using list in python

# Stack is Last In First Out data structure
stack = []

stack.append(1)
stack.append(2)
stack.append(3)  # 3 is top element of stack at this point

print(stack)  # [1, 2, 3]

top_element = stack.pop()
print(top_element)  # 3
print(stack.pop())  # 2
print(stack.pop())  # 1

print("Stack after being emptied: ")
print(stack)  # []
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #implement #stack #list #python
ADD COMMENT
Topic
Name
3+4 =