Last active
October 26, 2016 13:27
-
-
Save samwhitehall/e16c213819dcac2a4a13 to your computer and use it in GitHub Desktop.
Pringle Stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PringleStack: | |
def __init__(self): | |
self.stack = [] | |
def push(self, obj): | |
self.stack.append(obj) | |
def pop(self): | |
while len(self.stack) > 0: | |
yield self.stack.pop() | |
stack = PringleStack() | |
stack.push(1) | |
stack.push(2) | |
stack.push(3) | |
# once you pop, you can't stop | |
print [item for item in stack.pop()] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment