Python實(shí)現(xiàn)隊(duì)列的方法
更新時(shí)間:2015年05月26日 11:57:15 作者:buaa_shang
這篇文章主要介紹了Python實(shí)現(xiàn)隊(duì)列的方法,實(shí)例分析了Python實(shí)現(xiàn)隊(duì)列的相關(guān)技巧,需要的朋友可以參考下
本文實(shí)例講述了Python實(shí)現(xiàn)隊(duì)列的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
#!/usr/bin/env python
queue = []
def enQ():
queue.append(raw_input('Enter new string: ').strip())
#調(diào)用list的列表的pop()函數(shù).pop(0)為列表的第一個(gè)元素
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()
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- python實(shí)現(xiàn)堆棧與隊(duì)列的方法
- python隊(duì)列queue模塊詳解
- Python實(shí)現(xiàn)簡(jiǎn)單多線程任務(wù)隊(duì)列
- 詳解Python中的四種隊(duì)列
- Python實(shí)現(xiàn)優(yōu)先級(jí)隊(duì)列結(jié)構(gòu)的方法詳解
- 棧和隊(duì)列數(shù)據(jù)結(jié)構(gòu)的基本概念及其相關(guān)的Python實(shí)現(xiàn)
- python隊(duì)列Queue的詳解
- Python多線程和隊(duì)列操作實(shí)例
- Python3 queue隊(duì)列模塊詳細(xì)介紹
- python 隊(duì)列詳解及實(shí)例代碼
- Python隊(duì)列的定義與使用方法示例
- python 隊(duì)列基本定義與使用方法【初始化、賦值、判斷等】
相關(guān)文章
Python3.4學(xué)習(xí)筆記之 idle 清屏擴(kuò)展插件用法分析
這篇文章主要介紹了Python3.4 idle 清屏擴(kuò)展插件用法,簡(jiǎn)單分析了idle清屏的幾種方法及idle清屏插件的相關(guān)使用技巧,需要的朋友可以參考下2019-03-03
pycharm最新免費(fèi)激活碼至2099年(21.3.18親測(cè)可用)
這篇文章主要介紹了pycharm最新的激活碼及激活碼的使用方法,幫助大家更好的利用pycharm學(xué)習(xí)python,感興趣的朋友可以了解下。2021-03-03
Django項(xiàng)目之Elasticsearch搜索引擎的實(shí)例
今天小編就為大家分享一篇Django項(xiàng)目之Elasticsearch搜索引擎的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-08-08
Python簡(jiǎn)單實(shí)現(xiàn)區(qū)域生長(zhǎng)方式
今天小編就為大家分享一篇Python簡(jiǎn)單實(shí)現(xiàn)區(qū)域生長(zhǎng)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-01-01

