国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現隊列的方法

2020-02-23 01:25:39
字體:
來源:轉載
供稿:網友

本文實例講述了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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吴忠市| 海原县| 新郑市| 卢湾区| 贵港市| 梁河县| 滨海县| 拜城县| 繁昌县| 永胜县| 仁寿县| 交城县| 盐边县| 馆陶县| 乌兰县| 溧水县| 三门县| 双城市| 鄂托克前旗| 微博| 奉新县| 拜泉县| 古田县| 金平| 凤城市| 婺源县| 天长市| 凤凰县| 墨竹工卡县| 武夷山市| 张家界市| 博兴县| 杂多县| 桃园县| 子长县| 郓城县| 远安县| 花莲市| 栖霞市| 淮北市| 永清县|