class Stack(object): def __init__(self): self.contents = [] def __repr__(self): """Return a string representation of the Stack. The contents are listed from bottom to top in angle brackets.""" return str(self.contents).replace('[','<').replace(']','>') def is_empty(self): """Returns a boolean: whether self is an empty Stack.""" return self.contents==[] def height(self): """Returns the number of elements contained in self.""" return len(self.contents) def top(self): """Returns the top element of self.""" assert self.height() > 0 return self.contents[-1] def pop(self): """Modifies self by eliminating the top element.""" assert self.height() > 0 self.contents.pop() def push(self, item): """Modifies self by adding a new item on top. arguments: self -- an RA_stack item -- an arbitrary value to be added to the top""" self.contents.append(item) """ s = Stack() for e in range(10): s.push(e) print s print s.top() s.pop() print s.top() s.pop() print s """