Wdrożenie stosu za pomocą listy w 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)  # []
Wissam