创建双向队列
import collections d = collections.deque()
append(往右边添加一个元素)
import collections d = collections.deque() d.append(1) d.append(2)print(d)#输出:deque([1, 2])
appendleft(往左边添加一个元素)
import collections d = collections.deque() d.append(1) d.appendleft(2)print(d)#输出:deque([2, 1])
clear(清空队列)
import collections d = collections.deque() d.append(1) d.clear()print(d)#输出:deque([])
copy(浅拷贝)
import collections d = collections.deque() d.append(1) new_d = d.copy()print(new_d)#输出:deque([1])
count(返回指定元素的出现次数)
import collections d = collections.deque() d.append(1) d.append(1)print(d.count(1))#输出:2
extend(从队列右边扩展一个列表的元素)
import collections d = collections.deque() d.append(1) d.extend([3,4,5])print(d)#输出:deque([1, 3, 4, 5])
extendleft(从队列左边扩展一个列表的元素)
import collections d = collections.deque() d.append(1) d.extendleft([3,4,5])print(d)# # #输出:deque([5, 4, 3, 1])
index(查找某个元素的索引位置)
import collections d = collections.deque() d.extend(['a','b','c','d','e'])print(d)print(d.index('e'))print(d.index('c',0,3)) #指定查找区间#输出:deque(['a', 'b', 'c', 'd', 'e'])# 4# 2
insert(在指定位置插入元素)
import collections d = collections.deque() d.extend(['a','b','c','d','e']) d.insert(2,'z')print(d)#输出:deque(['a', 'b', 'z', 'c', 'd', 'e'])
pop(获取最右边一个元素,并在队列中删除)
import collections d = collections.deque() d.extend(['a','b','c','d','e']) x = d.pop()print(x,d)#输出:e deque(['a', 'b', 'c', 'd'])
popleft(获取最左边一个元素,并在队列中删除)
import collections d = collections.deque() d.extend(['a','b','c','d','e']) x = d.popleft()print(x,d)#输出:a deque(['b', 'c', 'd', 'e'])
remove(删除指定元素)
import collections d = collections.deque() d.extend(['a','b','c','d','e']) d.remove('c')print(d)#输出:deque(['a', 'b', 'd', 'e'])
reverse(队列反转)
import collections d = collections.deque() d.extend(['a','b','c','d','e']) d.reverse()print(d)#输出:deque(['e', 'd', 'c', 'b', 'a'])
rotate(把右边元素放到左边)
import collections d = collections.deque() d.extend(['a','b','c','d','e']) d.rotate(2) #指定次数,默认1次print(d)#输出:deque(['d', 'e', 'a', 'b', 'c'])
以上是python3 deque(双向队列)的详细介绍的详细内容。更多信息请关注PHP中文网其他相关文章!

pythonlistscanStoryDatatepe,ArrayModulearRaysStoreOneType,and numpyArraySareSareAraysareSareAraysareSareComputations.1)列出sareversArversAtileButlessMemory-Felide.2)arraymoduleareareMogeMogeNareSaremogeNormogeNoreSoustAta.3)

WhenyouattempttostoreavalueofthewrongdatatypeinaPythonarray,you'llencounteraTypeError.Thisisduetothearraymodule'sstricttypeenforcement,whichrequiresallelementstobeofthesametypeasspecifiedbythetypecode.Forperformancereasons,arraysaremoreefficientthanl

pythonlistsarepartofthestAndArdLibrary,herilearRaysarenot.listsarebuilt-In,多功能,和Rused ForStoringCollections,而EasaraySaraySaraySaraysaraySaraySaraysaraySaraysarrayModuleandleandleandlesscommonlyusedDduetolimitedFunctionalityFunctionalityFunctionality。

ThescriptisrunningwiththewrongPythonversionduetoincorrectdefaultinterpretersettings.Tofixthis:1)CheckthedefaultPythonversionusingpython--versionorpython3--version.2)Usevirtualenvironmentsbycreatingonewithpython3.9-mvenvmyenv,activatingit,andverifying

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomeSdata,performance-Caliticalcode,orinterFacingWithCcccode.1)同质性data:arrayssavememorywithtypedelements.2)绩效code-performance-clitionalcode-clitadialcode-critical-clitical-clitical-clitical-clitaine code:araysofferferbetterperperperformenterperformanceformanceformancefornalumericalicalialical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactssperformance.2)listssdonotguaranteeconeeconeconstanttanttanttanttanttanttanttanttimecomplecomecomecomplecomecomecomecomecomecomplecomectaccesslikearrikearraysodo。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

Dreamweaver CS6
视觉化网页开发工具

SublimeText3汉化版
中文版,非常好用

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中