Tag Archives: push
Implementing a Stack in python
To implement a Stack in python, we simply need to extend the existing list class! class Stack(list): def push(self, data): self.append(data) def tos(self): if self: return self[-1] def peek(self, index): if self and 0 <= index < len(self): return self[index] def __iter__(self): if self: ptr = len(self) – 1 while ptr >= 0: yield self[ptr] […]
Posted on May 10, 2012 by GauZ in Python, Technology
social_news_528
http://gauravpandey.com/wordpress/?p=528
Implementing a Stack in python
0
Login