我经常使用 Python 而不是伪代码。为此,我想要一个堆栈。我知道使用列表是要走的路(source),但我想使用myList.push
而不是myList.append
明确我使用堆栈。
我以为我可以做一些简单的事情,比如
myList.push = myList.append
为附加操作定义别名,但我得到
stack.push = stack.append
AttributeError: 'list' object has no attribute 'push'
是否存在将推送操作添加到列表的简短解决方案?
(它不应该弄乱我可运行的 Python 伪代码)