"Python" Constructs a dictionary type dictionary

Source: Internet
Author: User
Tags readline

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.