Dictionary type dictionary: is a dictionary containing a dictionary type, such as {' SSS ': {' ss ': ' DDDSDSDSD '}}
Construction Mode:
a={}b= "SSS" a[b]={}a[b][' ss '] = "DDDSDSDSD" Print a "{' sss ': {' ss ': ' DDDSDSDSD '}}
Application:
Import sys,os,reoui_dict={} # # #构造字典tmp_fp = open ("C:\\users\\administrator\\desktop\\mac.py-master\\mac.py-master\ \src\\macpy\\oui.txt ", ' RB ') while True:current_line=tmp_fp.readline () # # #读取一行进行如下判断 If current_line:m = Re. Match (R "^[0-9a-z]{6}", Current_line) # # #对所读到的行进行正则匹配 if M: # # #若匹配成功, then enter, otherwise go into the while loop read down TMP = current _line.split (' \t\t ') mac_24 = Tmp[0].split (') [0] if Oui_dict.get (mac_24, None): # # #get函数不返回none. Get gets oui_dict in Mac24 property value, none returned none oui_dict[mac_24][' com ' + = '/' + Tmp[1].strip () # #往字典类型字典添加数据 # # # #正则匹配成功再往下读3行 oui_dict[mac_24][' addr ' + = '/' + tmp_fp.readline (). Strip () oui_dict[ mac_24][' re '] + = '/' + tmp_fp.readline (). Strip () oui_dict[mac_24][' Co '] + = '/' + tmp_fp.readline (). Stri P () else:### #get函数返回none oui_dict[mac_24] = {} oui_dict[mac_24][' com ' = Tmp[1].s Trip () # #往字典类型字典添加数据 # # # #正则匹配成功再往下读3行 oui_dict[mac_24][' addr ' = Tmp_fp.readline (). Strip () oui_dict[mac_24][ ' re '] = Tmp_fp.readline (). Strip () oui_dict[mac_24][' Co ' = Tmp_fp.readline (). Strip () else:## #文档读到再无数据跳出w Hile Loop break
The oui.txt documentation is as follows:
"Python" Constructs a dictionary type dictionary