1. 程式人生 > >python[數據]--隊列,堆,優先級隊列

python[數據]--隊列,堆,優先級隊列

根據 pop 相同 lambda 隊列 max pytho 優先級 eap

隊列:from collections import deque;實現保存最後幾條歷史記錄,list = deque(maxlen=6),那麽超過六條記錄會刪除之前的記錄。

堆:import heapq;最大特點是第一彈出的元素總是堆中最小的元素;list=[1,2,3] heap=heapq.heapify(list) ,nlargest(3,數據,key=lambda) nsmallest()

優先級隊列:堆中的元素(-優先級,序號,item)這樣即可實現優先級,優先級越高最先pop出堆,優先級相同,根據index先後入堆順序pop

    

python[數據]--隊列,堆,優先級隊列