Dictionary Operations
A. Increase
1>>> info["stu1104"] ="ABC"2>>>Info3{'stu1102':'x5456','stu1104':'ABC','stu1103':'Mali','stu1101':'Wu'}B. Modifications
1>>> info['stu1101'] ="Xinge"2>>>Info3{'stu1102':'x5456','stu1103': Mali', 'Stu1101': 'Xinge'}C. Delete
1>>>Info2{'stu1102':'Longze Luola','stu1103':'Xiaoze Maliya','stu1101':'Enrique'}3>>> Info.pop ("stu1101")#Standard Delete Posture4 'Enrique'5>>>Info6{'stu1102':'Longze Luola','stu1103':'Xiaoze Maliya'}7>>>delinfo['stu1103']#remove it in a different position .8>>>Info9{'stu1102':'Longze Luola'}Ten>>> One>>> A>>> ->>> info = {'stu1102':'Longze Luola','stu1103':'Xiaoze Maliya'} ->>>Info the{'stu1102':'Longze Luola','stu1103':'Xiaoze Maliya'}#Random Delete ->>>Info.popitem () -('stu1102','Longze Luola') ->>>Info +{'stu1103':'Xiaoze Maliya'}D. Find
1>>> info = {'stu1102':'Longze Luola','stu1103':'Xiaoze Maliya'}2>>>3>>>"stu1102" inchInfo#Standard usage4 True5>>> Info.get ("stu1102")#Get6 'Longze Luola'7>>> info["stu1102"]#ditto, but look underneath.8 'Longze Luola'9>>> info["stu1105"]#If a key does not exist, it will be an error, get will not, not exist only return noneTen Traceback (most recent): OneFile"<stdin>", Line 1,inch<module> AKeyerror:'stu1105'E. Getting key values
1 #Values2>>>info.values ()3Dict_values (['Longze Luola','Xiaoze Maliya'])4 5 #Keys6>>>Info.keys ()7Dict_keys (['stu1102','stu1103'])
F. Merger
1 #Update2>>>Info3{'stu1102':'Longze Luola','stu1103':'Xiaoze Maliya','stu1106':'Alex'}4>>> B = {1:2,3:4,"stu1102":"deflorating Pull"}5>>>Info.update (b)6>>>Info7{'stu1102':'deflorating Pull', 1:2, 3:4,'stu1103':'Xiaoze Maliya','stu1106':'Alex'}
G. Deep copy
1 ImportCopy2 3N1 = {"K1":"Wu","K2": 123,"K3": ["Alex", 456]}4 5N4 = copy.deepcopy (n1)
H. Circulation
1 # Method 1 2 for inch Info: 3 print(Key,info[key])4 5# Method 2 6 for inch # will first turn the dict into a list, the data in the big time Mo 7 print(k,v)
[Python Study Notes] Dictionary operation