Article From:https://www.cnblogs.com/songzhixue/p/9125083.html
 1 menu = {
 2     'Beijing':{
 3         'Sunrise':{
 4             'China World Trade Center':{
 5                 'CICC':{},
 6                 'HP':{},
 7                 'Standard Chartered Bank':{},
 8                 'CCTV':{},
 9             },
10             'Wangjing':{
11                 'Stranger':{},
12                 'Benz':{},
13                 '360':{},
14             },
15             'Village':{
16                 'Uniqlo':{},
17                 'apple':{},
18             },
19         },
20         'Changping':{
21             'Shahe':{
22                 'Old boy':{},
23                 'Artest bun':{},
24             },
25             'Tian Tong Yuan':{
26                 'Chain family':{},
27                 'I love my family':{},
28             },
29             'Huilongguan':{},
30         },
31         'Haidian':{
32             'Wudaokou':{
33                 'Google':{},
34                 'NetEase':{},
35                 'Sohu':{},
36                 'Sogou':{},
37                 'Quick hand':{},
38             },
39             'Zhongguancun':{
40                 'Youku':{},
41                 'Iqiyi':{},
42                 'Car home':{},
43                 'New Oriental':{},
44                 'tencent':{},
45             },
46         },
47     },
48     'Shanghai':{
49         'Pudong':{
50             'Lujiazui':{
51                 'CICC':{},
52                 'Goldman Sachs':{},
53                 'morgan':{},
54             },
55             'The Bund':{},
56         },
57         'Minhang':{},
58         'Jingan':{},
59     },
60     'Shandong':{
61         'Ji'nan':{},
62         'Qingdao':{},
63         'Texas':{
64             'Leling':{
65                 'Ding Zhen Zhen':{},
66                 'City Proper':{},
67             },
68             'Plain county':{},
69         },
70     },
71 }
72 current_layer = menu   #Realization of dynamic cycle
73 parent_layers = []   #Save all the parent sets, and the last element will always be a father set.
74 while True:
75     for key in current_layer:
76         print(key)
77     choice = input('>>>:').strip()
78     if len(choice) == 0:continue
79     if choice in current_layer:
80         parent_layers.append(current_layer)  #Before entering the next level, add the current layer to the list. When the user selects B, he can pick up the last element of the list.
81         current_layer = current_layer[choice]  #Change into the sublayer
82     elif choice == 'b':
83         if parent_layers:
84             current_layer = parent_layers.pop()  #Take out the last value of the list, which is the father set of the current level.
85     else:
86         print('Without this item')

 

Link of this Article: Three level menu (high on top)

Leave a Reply

Your email address will not be published. Required fields are marked *