#Dictionary features # . dict is unordered # . The key must be unique, so is born to deduplicate
dixt = { ' caicai ' :33, ' wuwu ' :22}
of = { ' xingming ' : ' caicai ' , " age " :33, " opne " :13421731046, " qq " :75738369 } #If the key xingming exists, modify it, if it does not exist, create of[ " xingming " ] = " Cai Cai " of[ " XingM " ] = " Cai Cai " # #delete del of [ " XingM " ] of.pop( " xingming " ) #Randomly delete of.popitem() # Find--If not found, return None, if found, return value print (of.get( " opne " )) # Find--If found, return True, if not found, return False print ( ' opne ' in of) print(of)
###多层嵌套 catalog = { "oumei":{"www01":["01","01"],"www02":"02","www03":"03"}, "rihan":{"www04":"04","www05":"05","www06":"06"}, "dalu":{"www07":"07","www08":"08","www09":"09"} } # ##Modify a value catalog[ " oumei " ][ " www01 " ][1] = " 08 " print (catalog)
# #Update if there is this dictionary, create b = { ' dalu ' : { ' www17 ' : ' 17 ' , ' www18 ' : ' 18 ' , ' www19 ' : ' 19 ' }} catalog.update(b) print(catalog)
#loop in dictionary for i in catalog: print (i,catalog[i])
# #The dict will be converted into a list first. When the amount of data is large, do not use for k, v in catalog.items(): print (k,v)