Skip to content

Instantly share code, notes, and snippets.

@JackMorris JackMorris/ Secret
Created Apr 12, 2014

What would you like to do?
class Stack:
def __init__(self):
# Empty stack represented with an empty list.
self.stack = []
def push(self, x):
# Append the item onto our list.
def pop(self):
# Pop the item off of our list.
return self.stack.pop()
def peek(self):
# As long as it isn't empty, return the last item in our list.
if len(self.stack) > 0:
return self.stack[-1] # Index -1 = last element.
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.