字典-{}
-->字典用於以鍵:值對的形式儲存資料值。
-->字典是一個有序的、可更改的、不允許重複的集合。
-->在字典中,每個元素都可以透過它們的鍵來訪問,而不是透過索引。
-->如果字典不包含該鍵,則輸出將為「KeyError」。
範例:
thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } student = {"name":"raja", "class":5} print(thisdict) print(student)
輸出:
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964} {'name': 'raja', 'class': 5}
練習:使用巢狀循環找出字串中的字元
1.找出字串中每個字母的頻率
s = 'guruprasanna' name = list(s) j = 0 while j<len key="name[j]" count="1" i="j+1" if while name print j> <p>輸出:<br> </p> <pre class="brush:php;toolbar:false">g 1 u 2 r 2 p 1 a 3 s 1 n 2
*2。字母只出現一次 *
s = 'guruprasanna' name = list(s) j = 0 while j<len key="name[j]" count="1" i="j+1" if while name and print j> <p>輸出:<br> </p> <pre class="brush:php;toolbar:false">g 1 p 1 s 1
3。最常見的字母
s = 'guruprasanna' name = list(s) j = 0 while j<len key="name[j]" count="1" i="j+1" if while name and print j> <p>輸出:<br> </p> <pre class="brush:php;toolbar:false">u 2 r 2 a 3 n 2
4。第一個不重複的字母
s = 'guruprasanna' name = list(s) j = 0 while j<len key="name[j]" count="1" i="j+1" if while name and print break j> <p>輸出:<br> </p> <pre class="brush:php;toolbar:false">g 1
5。第一個重複的字母
s = 'guruprasanna' name = list(s) j = 0 while j<len key="name[j]" count="1" i="j+1" if while name and print break j> <p><strong>6。最後一個不重複的字母</strong><br> </p> <pre class="brush:php;toolbar:false">last = ' ' last_count = 0 s = 'guruprasanna' name = list(s) j = 0 while j<len key="name[j]" count="1" i="j+1" if while name and last="key" last_count="count" j print> <p>輸出:<br> </p> <pre class="brush:php;toolbar:false">s 1
7。最後重複的字母
last = ' ' last_count = 0 s = 'guruprasanna' name = list(s) j = 0 while j<len key="name[j]" count="1" i="j+1" if while name and last="key" last_count="count" j print> <p>輸出:<br> </p> <pre class="brush:php;toolbar:false">n 2
8。最常見的字母
s = 'guruprasanna' name = list(s) j = 0 last = ' ' last_count = 0 while j<len key="name[j]" count="1" i="j+1" if while name and>last_count: last = key last_count = count j+=1 print(last, last_count) </len>
9。元音出現頻率 (a,e,i,o,u)
vowels = ['a','e','i','o','u'] last = ' ' last_count = 0 s = 'guruprasanna' name = list(s) j = 0 while j<len key="name[j]" if in vowels: count="1" i="j+1" while name print j> <p>輸出:<br> </p> <pre class="brush:php;toolbar:false">u 2 a 3
以上是Python day-Dictionary,使用嵌套循環的字元頻率的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文討論了版本3.10中介紹的Python的新“匹配”語句,該語句與其他語言相同。它增強了代碼的可讀性,並為傳統的if-elif-el提供了性能優勢

Python中的功能註釋將元數據添加到函數中,以進行類型檢查,文檔和IDE支持。它們增強了代碼的可讀性,維護,並且在API開發,數據科學和圖書館創建中至關重要。

本文討論了Python中的單位測試,其好處以及如何有效編寫它們。它突出顯示了諸如UNITSEST和PYTEST之類的工具進行測試。

文章討論了Python的\ _ \ _ Init \ _ \ _()方法和Self在初始化對象屬性中的作用。還涵蓋了其他類方法和繼承對\ _ \ _ Init \ _ \ _()的影響。

本文討論了python中@classmethod,@staticmethod和實例方法之間的差異,詳細介紹了它們的屬性,用例和好處。它說明瞭如何根據所需功能選擇正確的方法類型和DA

Inpython,YouAppendElementStoAlistusingTheAppend()方法。 1)useappend()forsingleelements:my_list.append(4).2)useextend()orextend()或= formultiplelements:my_list.extend.extend(emote_list)ormy_list = [4,5,6] .3)useInsert()forspefificpositions:my_list.insert(1,5).beaware


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

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

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

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

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

禪工作室 13.0.1
強大的PHP整合開發環境