Skip to content

Instantly share code, notes, and snippets.

@seanjensengrey
Last active February 4, 2022 00:13
Show Gist options
  • Save seanjensengrey/0d5a75e9adcd5aabe569f6d6db165a5c to your computer and use it in GitHub Desktop.
Save seanjensengrey/0d5a75e9adcd5aabe569f6d6db165a5c to your computer and use it in GitHub Desktop.
class StackModule:
def __init__(self):
self.items = []
def __repr__(self):
return repr(self.items)
def push(self, value):
self.items.append(value)
def pop(self):
return self.items.pop()
def add(self):
right = self.pop()
left = self.pop()
self.push(left + right)
def sub(self):
right = self.pop()
left = self.pop()
self.push(left - right)
def mul(self):
right = self.pop()
left = self.pop()
self.push(left * right)
def div(self):
right = self.pop()
left = self.pop()
self.push(left / right)
def rotate(self):
left = self.items[1:]
right = [self.items[0]]
self.items = left + right
def swap(self):
self.items[-2:] = self.items[-2:][::-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment