[Terry Notes] python Level 3 menu,

Source: Internet
Author: User

[Terry Notes] python Level 3 menu,

Output the Level 3 menu, select it, and display it layer by layer. "B" returns to the level 1 menu.

1 menu = {2 'beijing': {3 'haidian ': {4 'wudaokou': {5 'soho ': {}, 6 'netease ':{}, 7 'Google ': {} 8}, 9 'zhongguancun': {10 'iqiyi ':{}, 11 'car home' :{}, 12 'youku ':{}, 13}, 14' ': {15 'Baidu': {}, 16}, 17}, 18 'changping ': {19 'shahe': {20 'old boys ': {}, 21 'beihang ':{}, 22}, 23 'tiantongyuan' :{}, 24 'longguan ':{}, 25}, 26 'chaoyang ': {}, 27 'dongcheng ':{}, 28}, 29 'shanghai': {30 'minhang': {31 "People's Square": {32 'chicken shops ': {} 33} 34}, 35 'zhabei ': {36 'train barri': {37 'ctrip': {} 38} 39}, 40 'pudong ':{}, 41}, 42 'shandong ': {}, 43}

 

Second force youth edition:
 1 while True: 2     for key in menu: 3         print(key) 4     choice = input(">>>:") 5     if len(choice) == 0: continue 6     if choice not in menu:continue 7     while True: 8         for key2 in menu[choice]: 9             print(key2)10         choice2 = input(">>>:")11         if len(choice2) == 0: continue12         if choice2 == "b": break13         if choice2 not in menu[choice]: continue14         while True:15             for key3 in menu[choice][choice2]:16                 print(key3)17             choice3 = input(">>>:")18             if len(choice3) == 0: continue19             if choice3 == "b": break20             if choice3 not in menu[choice][choice2]: continue21             while True:22                 for key4 in menu[choice][choice2][choice3]:23                     print(key4)24                 choice4 = input(">>>:")25                 if len(choice4) == 0: continue26                 if choice4 == "b": break27                 if choice4 not in menu[choice][choice2][choice3]: continue

 

Youth edition:

 1 current_level = menu 2 last_level = [] 3 while True: 4     for key in current_level: 5         print(key) 6     choice = input(">>>:") 7     if len(choice) == 0:continue 8     if choice == "b": 9         if not last_level : break10         current_level = last_level[-1]11         last_level.pop()12     if choice not in current_level:continue13     last_level.append(current_level)14     current_level = current_level[choice]

 

Related Article

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.