Stack data structure in python

前端 未结 7 1465
轮回少年
轮回少年 2021-02-02 09:24

I have 2 issues with the code below:

  1. push(o) throws an exception TypeError: can only assign an iterable.
  2. Should I throw an exception if pop()

相关标签:
7条回答
  • 2021-02-02 09:50

    I won't talk about the list structure as that's already been covered in this question. Instead I'll mention my preferred method for dealing with stacks:

    I always use the Queue module. It supports FIFO and LIFO data structures and is thread safe.

    See the docs for more info. It doesn't implement a isEmpty() function, it instead raises a Full or Empty exception if a push or pop can't be done.

    0 讨论(0)
提交回复
热议问题