Python-Level 7 dictionary query and python dictionary Query

Source: Internet
Author: User

Python-Level 7 dictionary query and python dictionary Query

1 #-*-coding: UTF-8-*-2 3 4 # job requirements: 5 # five menus of municipalities, provinces, municipalities, counties, districts, and sub-streets; 6 # Step by step to all layers 7 # exit to the previous Layer 8 # exit program at any time 9 10 11 mapChina = {12 "People's Republic of China": {13 "Beijing ": {14 "city": {15 "Dongcheng District" :{}, 16 "Xicheng district" :{}, 17 "Chaoyang District" :{}, 18 "Haidian District ":{}, 19 "Shijingshan district" :{}, 20 "Fengtai District" :{}, 21 }, 22 "remote suburb": {23 "Shunyi District" :{}, 24 "Huairou district ": {}, 25 "Miyun district" :{}, 26 "Yanqing County" :{}, 27 "Changping District" :{}, 28 "Pinggu district" :{}, 29 "Mentougou District ": {}, 30 "Fangshan District" :{}, 31 "Tongzhou District" :{}, 32}, 33}, 34 "Hunan": {35 "Changsha City": {36 "Wangcheng county" :{}, 37 "Ningxiang County" :{}, 38 "Liuyang county ": {}, 39 "Changsha county": {40 "Fulin Town" :{}, 41 "Baisha township" :{}, 42 "Gaoqiao Town" :{}, 43 "Huanghua Town ": {}, 44 "muyun Town" :{}, 45 "Juma Town" :{}, 46 "Guanyuan Town" :{}, 47 "Huanghua Town ": {48 "quantang resettlement community": {49 "Zoomlion": {50 "thoughts build the future": "No interest, Bo Hou long distance", 51}, 52 "many schools ": {53 "Schools": "various Hunan snacks", 54}, 55}, 56 "Huanghua airport" :{}, 57 "Hunan Agricultural University ":{}, 58 "xuteli Park" :{}, 59 60 61}, 62}, 63}, 64 "Zhuzhou city": {65 "PiXian ":{}, 66 "Chaling" :{}, 67 "Yanling" :{}, 68 "Fuling" :{}, 69 }, 70 "Xiangtan city" :{}, 71 "Hengyang City ": {}, 72 "Shaoyang City" :{}, 73 "Yueyang City" :{}, 74 "Changde City" :{}, 75 "Zhangjiajie City" :{}, 76 "Yiyang City ": {}, 77 "Chenzhou City" :{}, 78 "Yongzhou City" :{}, 79 "loudi city" :{}, 80 "HuaiHua City ":{}, 81 "Xiangxi Minority Autonomous Region" :{}, 82 }, 83 "Chongqing" :{}, 84 "Sichuan" :{}, 85 "Jiangxi ":{}, 86 "Shaanxi" :{}, 87 "Fujian" :{}, 88 "Shanghai" :{}, 89 "Zhejiang" :{}, 90 "other provinces, municipalities, autonomous regions and municipalities ": {}, 91} 92} 93 94 # print (type (mapChina ["People's Republic of China"]) 95 # print (MapChina ["People's Republic of China"] ["Hunan"]) 96 # print (mapChina ["People's Republic of China"] ["Hunan"] ["Changsha City"] ["Changsha county"] ["Huanghua Town"] ["quantang resettlement community"] ['zoomlion ']) 97 98 99 choose_list = [] 100 mapChina_new = mapChina101 102 print ("Enter the 'B' key to return to the previous layer, and enter the 'q' key to exit the initial interface, enter 'qq' to exit the program. ") 103 print (mapChina. keys () 104 105 106 while True: 107 108 choose = input ("enter the name of the region to be accessed:") 109 if choose = 'qq ': 110 break111 elif choose = 'q': 112 mapChina_new = mapChina113 continue114 elif choose = "B": 115 if mapChina_new = mapChina: 116 continue117 else: 118 mapChina_new = large () 119 for key1 in mapChina_new.keys (): 120 print (key1) 121 elif choose in mapChina_new.keys (): 122 choose_list. Append (mapChina_new) 123 mapChina_new = mapChina_new [choose] 124 for key in mapChina_new.keys (): 125 print (key) 126 elif not mapChina_new.values (): 127 print ("this is the last layer, enter 'B' to return ") 128 continue129 else: 130 print (" Invalid Input. try Again! ")

 

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.