Python dictionary provides a simple three-level menu,
Data = {
"Beijing ":{
"Changping": {"shahe": ["oldboy", "test"], "tiantongyuan": ["linked property", "I love my family"]},
"Chaoyang": {"Wangjing": ["Mercedes-Benz", "momo"], "International trade": ["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 ("enter the name of any of the preceding provinces or municipalities >> :")
If choice_s in data:
While not exit_flag:
For I in data [choice_s]:
Print ("\ t", I)
Choice_q = input ("enter the name of any of the above cities >> :")
If choice_q in data [choice_s]:
While not exit_flag:
For I in data [choice_s] [choice_q]:
Print ("\ t", I)
Choice_j = input ("enter the name of any of the preceding streets >> :")
If choice_j in data [choice_s] [choice_q]:
For I in data [choice_s] [choice_q] [choice_j]:
Print ("\ t", I)
Last = input ("last layer, return by B >>> :")
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
Key points:
1. hierarchical relationship of dictionaries
2. break terminates this loop, and pass does nothing. It is a placeholder.
3. cleverly use exit_flag = False
While not exit_flag: