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