Level four menu implementation (Python)

Source: Internet
Author: User

menu_dict = {
' Shandong ': {
' Qingdao ': {
' Quartet ': {' Xinglong road ', ' Pingan road ', ' Hangzhou Road '},
' Huangdao ': {},
' Laoshan ': {}
},
' Jinan ': {
' Licheng ': {},
' Huaiyin ': {},
' High-tech ': {}
},
},
' Jiangsu ': {
' Suzhou ': {
' Canglang ': {},
' Xiangcheng ': {},
' Pingjiang ': {}
},
' Nanjing ': {
' Baixia ': {},
' Qinhuai ': {},
' Pukou ': {}
}
}
}

Current_layer = menu_dict
parent_layers = [] #把不同层级的字典保存在列表中 (nested dictionary in list) [menu_dict,menu_dict[Province], .... ], to the last level, the list looks like this.
#parent_layers [0]={' Shandong ': {' Qingdao ': {' Sifang ': {' Hangzhou road ', ' Xinglong Road ', ' Pingan Road '}, ' Huangdao ': {}, ' Laoshan ': {}}, ' Jinan ': {' Licheng ': {}, ' Huaiyin ': {}, ' High-tech ': {} }}, ' Jiangsu ': {' Suzhou ': {' Canglang ': {}, ' Xiangcheng ': {}, ' Pingjiang ': {}}, ' Nanjing ': {' Baixia ': {}, ' Qinhuai ': {}, ' Pukou ': {} }}
#parent_layers[1]={' qingdao ': {' Sifang ': {' Hangzhou road ', ' Xinglong Road ', ' Pingan Road '}, ' Huangdao ': {}, ' Laoshan ': {}}, ' Jinan ': {' Licheng ': {}, ' Huaiyin ': {}, ' High ': {}}}
 #parent_layers[2]={' quartet ': {' Hangzhou road ', ' Xinglong Road ', ' Pingan Road '}, ' Huangdao ': {}, ' Laoshan ': {}} whileTrue:
 For key in Current_layer:
Print (key)
Choice = input (">>:"). Strip ()
If len (choice) = = 0:
Continue
If choice in Current_layer:
Parent_layers.append (Current_layer)

Current_layer = Current_layer[choice]
elif Choice = = ' B ':
If Parent_layers:
Current_layer = Parent_layers.pop ()
Else
Print ("No this item")

Level four menu implementation (Python)

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.