Skip to content

Stack

my_stack = []

Add O(1)

my_stack.append(item)

Pop O(1)

my_stack.pop()

Peek O(1)

my_stack[-1]

Size O(1)

len(my_stack)

Example

stack = [3, 4, 5]
stack.append(6)
stack.append(7)
stack
stack.pop()
stack
stack.pop()
stack.pop()
stack