新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:pythonupdate合并字典的方法
1、每次調(diào)用update()現(xiàn)有鍵的值,鍵都會更新為新值。

創(chuàng)新互聯(lián)公司是專業(yè)的旌陽網(wǎng)站建設公司,旌陽接單;提供網(wǎng)站制作、成都做網(wǎng)站,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行旌陽網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
在這種情況下,您將無法使用不同的范圍來優(yōu)先訪問重復密鑰。
2、使用update(),為給定鍵提供的最后一個值將永遠占上風。在循環(huán)中創(chuàng)建常規(guī)字典需要O(nm),而從最終字典中檢索一個鍵需要O(1)。
實例
>>> for_adoption = {"dogs": 10, "cats": 7, "pythons": 3}
>>> vet_treatment = {"cats": 2, "dogs": 1}
>>> # Merge dictionaries with .update()
>>> pets = {}
>>> pets.update(for_adoption)
>>> pets.update(vet_treatment)
>>> pets
{'dogs': 1, 'cats': 2, 'pythons': 3}
以上就是python update合并字典的方法,希望對大家有所幫助。更多Python學習指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:pythonupdate合并字典的方法
文章網(wǎng)址:http://m.fisionsoft.com.cn/article/dhpopeh.html


咨詢
建站咨詢
