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

首頁 > 編程 > Python > 正文

Python實現隊列的方法

2019-11-25 17:22:28
字體:
來源:轉載
供稿:網友

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 威海市| 福建省| 永安市| 宁明县| 寻甸| 封开县| 淳化县| 沂水县| 阳山县| 青铜峡市| 深圳市| 诏安县| 建宁县| 巩义市| 忻城县| 桐庐县| 双鸭山市| 保德县| 和林格尔县| 开封县| 巴彦淖尔市| 武平县| 呼图壁县| 宣威市| 长兴县| 宾川县| 绥中县| 原阳县| 丹凤县| 花莲县| 济源市| 彭泽县| 澄城县| 双峰县| 东乌珠穆沁旗| 桓仁| 南平市| 鱼台县| 新巴尔虎左旗| 江北区| 新野县|