-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyStack.py
More file actions
33 lines (23 loc) · 788 Bytes
/
myStack.py
File metadata and controls
33 lines (23 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import ast
class Stack :
def __init__(self,prelist=""):
if prelist == "":
self._theItems = list()
else:
self._theItems = ast.literal_eval(prelist)
def isEmpty( self ):
return len( self ) == 0
def __len__ ( self ):
return len( self._theItems )
def peek( self ):
assert not self.isEmpty(),"Cannot peek at an empty stack"
return self._theItems[-1]
def pop( self ):
assert not self.isEmpty(),"Cannot pop from an empty stack"
return self._theItems.pop()
def push( self, item ):
self._theItems.append( item )
def __str__(self):
return str(self._theItems)
if __name__ == "__main__":
pass