建立雙向佇列
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中文網其他相關文章!

使用NumPy創建多維數組可以通過以下步驟實現:1)使用numpy.array()函數創建數組,例如np.array([[1,2,3],[4,5,6]])創建2D數組;2)使用np.zeros(),np.ones(),np.random.random()等函數創建特定值填充的數組;3)理解數組的shape和size屬性,確保子數組長度一致,避免錯誤;4)使用np.reshape()函數改變數組形狀;5)注意內存使用,確保代碼清晰高效。

播放innumpyisamethodtoperformoperationsonArraySofDifferentsHapesbyAutapityallate AligningThem.itSimplifififiesCode,增強可讀性,和Boostsperformance.Shere'shore'showitworks:1)較小的ArraySaraySaraysAraySaraySaraySaraySarePaddedDedWiteWithOnestOmatchDimentions.2)

forpythondataTastorage,choselistsforflexibilityWithMixedDatatypes,array.ArrayFormeMory-effficityHomogeneousnumericalData,andnumpyArraysForAdvancedNumericalComputing.listsareversareversareversareversArversatilebutlessEbutlesseftlesseftlesseftlessforefforefforefforefforefforefforefforefforefforlargenumerdataSets; arrayoffray.array.array.array.array.array.ersersamiddreddregro

文章討論了由於語法歧義而導致的Python中元組理解的不可能。建議使用tuple()與發電機表達式使用tuple()有效地創建元組。 (159個字符)

本文解釋了Python中的模塊和包裝,它們的差異和用法。模塊是單個文件,而軟件包是帶有__init__.py文件的目錄,在層次上組織相關模塊。

文章討論了Python中的Docstrings,其用法和收益。主要問題:Docstrings對於代碼文檔和可訪問性的重要性。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。