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)文章
Python?pyecharts?Map地圖數(shù)據(jù)不顯示的原因及完美解決
這篇文章主要給大家介紹了關(guān)于Python?pyecharts?Map地圖數(shù)據(jù)不顯示的原因及解決辦法,pyecharts是一款將python與echarts結(jié)合的強(qiáng)大的數(shù)據(jù)可視化工具,文中通過(guò)圖文以及代碼示例介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12CentOS下使用yum安裝python-pip失敗的完美解決方法
這篇文章主要介紹了CentOS下使用yum安裝python-pip失敗的完美解決方法,需要的朋友可以參考下2017-08-08用python簡(jiǎn)單實(shí)現(xiàn)mysql數(shù)據(jù)同步到ElasticSearch的教程
今天小編就為大家分享一篇用python簡(jiǎn)單實(shí)現(xiàn)mysql數(shù)據(jù)同步到ElasticSearch的教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-05-05python基礎(chǔ)while循環(huán)及if判斷的實(shí)例講解
下面小編就為大家?guī)?lái)一篇python基礎(chǔ)while循環(huán)及if判斷的實(shí)例講解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08