Link to module Stack
Duncan Booth
duncan.booth at invalid.invalid
Sat Jan 9 06:40:42 EST 2010
Dave Angel <davea at ieee.org> wrote:
> or even better, without the extra local var:
>
> def pop (self):
> if len(self.__heap) == 0:
> raise InnerInterpreterError, "stack underflow"
> return self.__heap.pop(1)
pop(1)?
Anyway if would be simpler and almost certainly faster to not bother
checking before the pop:
def pop(self):
try:
return self.__heap.pop()
except IndexError:
raise InnerInterpreterError, "stack underflow"
and if performance mattered the OP might even consider pre-binding the pop
method in __init__:
self.__pop = self.__heap.pop
but that's probably premature optimisation.
> P.S. - I'm puzzled why the OP even put this message here. There's no
> question posted with it.
Me too. It's a repost of something from 2004. Bizarre.
More information about the Python-list
mailing list