首页 > 代码库 > Python实战之双向队列deque/queue学习笔记及简单练习
Python实战之双向队列deque/queue学习笔记及简单练习
[‘__add__‘, ‘__bool__‘, ‘__class__‘, ‘__contains__‘, ‘__copy__‘, ‘__delattr__‘, ‘__delitem__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__gt__‘, ‘__hash__‘, ‘__iadd__‘, ‘__imul__‘, ‘__init__‘, ‘__init_subclass__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__mul__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__reversed__‘, ‘__rmul__‘, ‘__setattr__‘, ‘__setitem__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘append‘, ‘appendleft‘, ‘clear‘, ‘copy‘, ‘count‘, ‘extend‘, ‘extendleft‘, ‘index‘, ‘insert‘, ‘maxlen‘, ‘pop‘, ‘popleft‘, ‘remove‘, ‘reverse‘, ‘rotate‘]
from collections import deque d = deque() print(dir(d)) d.append(1) d.append(10) d.appendleft(1) print(d) # deque([1, 1, 10]) # d.clear() # print(d) # deque([]) b = d.copy() # print(b) # deque([1, 1, 10]) # d.extend(b) # print(d) # deque([1, 1, 10, 1, 1, 10]) # d.extendleft(b) # print(d) # deque([10, 1, 1, 1, 1, 10, 1, 1, 10]) print(d.count(1)) # 2 print(d.index(10)) # 2 d.insert(10,15) # d.remove(1) # deque([1, 10, 15]) print(d) d.rotate(3) # deque([1, 10, 15, 1]) print(d)
from queue import Queue q = Queue() q.put(‘123‘) q.put(‘456‘) print(q.qsize()) print(q.get_nowait()) print(q.get_nowait()) print(q.qsize()) # 2 # 123 # 456 # 0
Python实战之双向队列deque/queue学习笔记及简单练习
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。