最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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ì)有所幫助。

相關(guān)文章

最新評(píng)論

梁平县| 建始县| 鄂托克前旗| 翼城县| 沙河市| 衡阳市| 河间市| 林芝县| 安乡县| 报价| 开平市| 修武县| 刚察县| 慈利县| 延长县| 保亭| 通许县| 陇西县| 肥城市| 中山市| 壤塘县| 罗甸县| 银川市| 长春市| 盐亭县| 乃东县| 富蕴县| 营口市| 抚松县| 乌拉特前旗| 汶川县| 田阳县| 麻城市| 当涂县| 嵊州市| 凌海市| 冀州市| 罗城| 洞头县| 壶关县| 汽车|