新手学Python 外篇一 队列的实现
2013-10-29 09:10
363 查看
queue = [] def enQ(): queue.append(raw_input('Enter new string:').strip()) def deQ(): if len(queue) == 0: print 'Cannot pop from an empty queue!' else: print 'Removed[',queue.pop(0),']' def viewQ(): print queue CMDs ={'e':enQ,'d':deQ,'v':viewQ} def showmenu(): pr = """ (E)nqueue (D)equeue (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 '\n You picked:[%s]'%choice if choice not in 'devq': print 'Invalid option ,try again' else: break if choice == 'q': break CMDs[choice]() if __name__=='__main__': showmenu()
相关文章推荐
- UliPad 初体验----python 开发利器
- python 开发利器
- 刚开始学Python,坚持下去
- Python Cookbook学习记录 ch2_9/16_2013/10/28
- Python之Threading模块
- python--Tkinter教程之Canvas篇(3)
- 一步一步学编程之Python(四)
- 初学python
- python 发行包
- So cute are you python 14
- 将aaaa替换成aaba 分类: python 小练习 2013-10-28 18:28 246人阅读 评论(0) 收藏
- 使用生成器返回fibs列表 分类: python Module python基础学习 2013-10-28 18:19 283人阅读 评论(0) 收藏
- python使用技巧(一)
- python
- python中的生成器(generator)
- python中的生成器(generator) 分类: python Module python基础学习 2013-10-28 17:41 310人阅读 评论(0) 收藏
- 检测网站挂马程序(Python)
- [笔记]--用Python获取Windows系统语言
- 用Python实现Excel导出Json文件
- 17个新手常见Python运行时错误