Python实现队列的方法
作者:buaa_shang 时间:2023-08-29 06:45:30
本文实例讲述了Python实现队列的方法。分享给大家供大家参考。具体实现方法如下:
#!/usr/bin/env python
queue = []
def enQ():
queue.append(raw_input('Enter new string: ').strip())
#调用list的列表的pop()函数.pop(0)为列表的第一个元素
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 '\nYou 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()
希望本文所述对大家的Python程序设计有所帮助。
标签:Python,队列
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 利用pandas将arff文件转csv文件的方法
2021-05-31 05:49:34
Opencv实现眼睛控制鼠标的实践
2023-07-04 11:21:52
![](https://img.aspxhome.com/file/2023/2/67862_0s.jpg)
Pygame框架实现飞机大战
2023-09-15 02:14:24
![](https://img.aspxhome.com/file/2023/2/108032_0s.jpg)
Js sort排序使用方法
2023-10-19 10:20:55
MySQL8.0.18配置多主一从
2024-01-15 01:23:15
FCKEidtor 自动统计输入字符个数(IE)
2023-01-28 10:07:54
![](https://img.aspxhome.com/file/2023/0/71290_0s.gif)
PHP中的一些常用函数收集
2023-10-09 02:06:06
php实现上传图片保存到数据库的方法
2024-05-09 14:48:35
![](https://img.aspxhome.com/file/2023/2/129382_0s.jpg)
利用Python写一个爬妹子的爬虫
2021-07-22 12:44:51
![](https://img.aspxhome.com/file/2023/1/72931_0s.png)
MySQL复合索引的深入探究
2024-01-22 21:12:48
![](https://img.aspxhome.com/file/2023/4/101364_0s.png)
Python2.7简单连接与操作MySQL的方法
2024-01-25 18:38:56
Django查询数据库的性能优化示例代码
2024-01-22 22:18:48
![](https://img.aspxhome.com/file/2023/7/112597_0s.png)
Python深拷贝与浅拷贝用法实例分析
2023-11-06 01:25:04
交互设计实用指南系列(2) –可及
2010-01-21 12:48:00
![](https://img.aspxhome.com/file/UploadPic/20101/21/sm11-73s.jpg)
Django model序列化为json的方法示例
2022-08-25 01:39:03
详解在OpenCV中实现的图像标注技术
2023-12-01 11:54:34
![](https://img.aspxhome.com/file/2023/3/99533_0s.jpg)
40个你可能不知道的Python技巧附代码
2021-09-26 13:56:58
Python图像运算之图像阈值化处理详解
2023-03-20 22:36:24
![](https://img.aspxhome.com/file/2023/5/85205_0s.png)
如何高效地访问记录集?
2009-11-22 19:25:00
pytorch 实现二分类交叉熵逆样本频率权重
2021-04-29 00:25:29
![](https://img.aspxhome.com/file/2023/5/90365_0s.png)