Skip to content

Instantly share code, notes, and snippets.

@computer-tutor
Created April 25, 2020 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save computer-tutor/b266f23ee1c1b2a1b91e8f22e2f5a4c4 to your computer and use it in GitHub Desktop.
Save computer-tutor/b266f23ee1c1b2a1b91e8f22e2f5a4c4 to your computer and use it in GitHub Desktop.
def push(stack, x):
stack.insert(0, x) # this way top is always at the front
def pop(stack):
return stack.pop(0) # pops from the front because it is the top
l = [4, 5, 6, 7]
push(l, 8) # l becomes [8, 4, 5, 6, 7] x = pop(l)
print(l)
pop(l)
print(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment