Python核心编程:用列表模拟堆栈
来源:互联网 发布:优酷mac下的视频在哪里 编辑:程序博客网 时间:2024/06/05 09:46
#!/usr/bin/env python
stack = []
def pushit():
stack.append(raw_input('Enter New string: ').strip())
def popit():
if len(stack)==0:
print 'cannot pop from an empty stack!'
else:
print 'remove[','stack.pop',']'
def viewstack():
print stack #calls str() internally
CMDs = {'u': pushit,'o': popit,'v': viewstack}
def showmenu():
pr="""
p(U)sh
p(O)p
(V)iew
(Q)uit
ENter choice:"""
while True:
while True:
try:
choice = raw_input(pr).strip()[0].lower()
except (EOFError,KeyboardInterrupt,IndexError):
choice = 'q'
print'\nYou picked: [%s]' % choice
if choice not in 'uovq':
print 'Invalid option, try again'
else:
break
if choice == 'q':
break
CMDs[choice]()
if __name__ == '__main__':
showmenu()
stack = []
def pushit():
stack.append(raw_input('Enter New string: ').strip())
def popit():
if len(stack)==0:
print 'cannot pop from an empty stack!'
else:
print 'remove[','stack.pop',']'
def viewstack():
print stack #calls str() internally
CMDs = {'u': pushit,'o': popit,'v': viewstack}
def showmenu():
pr="""
p(U)sh
p(O)p
(V)iew
(Q)uit
ENter choice:"""
while True:
while True:
try:
choice = raw_input(pr).strip()[0].lower()
except (EOFError,KeyboardInterrupt,IndexError):
choice = 'q'
print'\nYou picked: [%s]' % choice
if choice not in 'uovq':
print 'Invalid option, try again'
else:
break
if choice == 'q':
break
CMDs[choice]()
if __name__ == '__main__':
showmenu()
1 0
- Python核心编程:用列表模拟堆栈
- 《Python核心编程(第2版)》读书笔记(6)之用列表模拟堆栈(关键词:Python/列表/堆栈/stack.py)
- WINDOWS核心编程--堆栈
- python核心编程笔记(5)- 列表,元组
- 用数组模拟堆栈
- Python 核心编程笔记_Chapter_6_Note_3 列表_列表内建函数
- windows核心编程--内存堆栈
- windows核心编程--内存堆栈
- Windows核心编程 第十八章 堆栈
- python 核心编程 练习题
- 《Python核心编程》目录
- Python核心编程笔记
- Python 核心编程 笔记
- python核心编程笔记
- python核心编程--笔记
- Python核心编程总结
- python核心编程--笔记
- Python核心编程
- item-based CF 推荐系统学习笔记
- 点击空白关闭键盘
- css 边框样式
- 写给自己程序员生涯开始的话
- C# 识别简单验证码遇到的问题
- Python核心编程:用列表模拟堆栈
- Linux手机设备不能识别的解决
- CSS篇 动画
- 点击删除按钮弹出对话框提示是否删除
- [LeetCode]Factorial Trailing Zeroes--javascript解法
- Syntax error on tokens, delete these tokens
- 深度学习-pipeline
- Windows10 IME占用过高临时解决办法
- 如果遇到无法响应或者没遇见过的bug