队列实现
1 python队列实现,使用队列的时候要用collections来实现,这样更方便,因为它有类似list的用法,而用deque模块实现的队列用的是get,put方法,
# python3里面用queue模块 from queue import Queue q = Queue() q.put(3) q.put(7) print(q.get()) # 3 print(q.get()) # 7 # 双端队列 from collections import deque d = deque() d.append(2) d.append(3) print(d) print(len(d)) print(d.pop()) print(d.popleft()) # deque([2, 3]) # 2 # 3 # 2
ttt
参考:https://blog.csdn.net/BTUJACK/article/details/83180902?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2