Link to module Stack
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Jan 9 04:25:08 EST 2010
On Sat, 09 Jan 2010 01:07:39 -0800, kzagradskiy wrote:
> class Stack:
> def __init__(self):
> self.__heap = []
A "heap" has a technical meaning in programming. To describe the
internals of a stack as "heap" will be disconcerting and confusing to
anyone who knows about stacks and heaps.
> def push (self, word):
> self.__heap.append (word)
> def pop (self):
> if len(self.__heap) == 0:
> raise InnerInterpreterError, "stack underflow"
"InnerInterpreterError" is the most inappropriate exception name I've
ever seen. It has nothing to do with the interpreter, it's a stack error.
> result = self.__heap[-1]
> del self.__heap[-1]
That is better written as result = self.__heap.pop().
--
Steven
More information about the Python-list
mailing list