Python dictionary implements a simple level three menu

Source: Internet
Author: User

data = {
"Beijing": {
"Changping": {"Shahe": ["Oldboy", "Test"], "Tian Tong Yuan": ["Link Property", "I love my Home"]},
"Chaoyang": {"wangjing": ["Mercedes-Benz", "Mo Mo"], "Guomao": ["CICC", "HP"], "dongzhimen": ["Advent", "Fetion"]},
"Haidian": {}
},
"Shandong": {
"Texas": {},
"Qingdao": {},
"Jinan": {}
},
"Guangdong": {
"Dongguan": {},
"Changshu": {},
"Foshan": {}
}
}
Exit_flag = False
While not exit_flag:
For I in data:
Print (i)
choice_s = input ("Please enter any of the above province or municipality name >>>:")
If choice_s in data:
While not exit_flag:
For I in data[choice_s]:
Print ("\ t", I)
Choice_q = input ("Please enter any of the above city names >>>:")
If Choice_q in data[choice_s]:
While not exit_flag:
For I in Data[choice_s][choice_q]:
Print ("\t\t", i)
Choice_j = input ("Please enter any of the street names above >>>:")
If Choice_j in Data[choice_s][choice_q]:
For I in Data[choice_s][choice_q][choice_j]:
Print ("\t\t", i)
last = input ("final layer, press B to return >>>:")
If last = = "B":
Pass
Elif last = = "Q":
Exit_flag = True
if Choice_j = = "B":
Break
elif Choice_j = = "Q":
Exit_flag = True
if choice_q = = "B":
Break
elif Choice_q = = "Q":
Exit_flag = True


Points:
1. The hierarchical relationship of dictionaries
2, break is to terminate this cycle, pass is nothing to do, a placeholder just
3. Clever use of Exit_flag = False

While not Exit_flag:

Python dictionary implements a simple level three menu

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.