Three-level menu Python notation (recursive notation)

Source: Internet
Author: User
Tags iqiyi

 data structure: Menu = {' Beijing ': {' Haidian ': {' Five crossings ': {' Soho ': {}, ' NetEase                ': {}, ' Google ': {}}, ' Zhongguancun ': {' Iqiyi ': {}, ' Autohome ': {},            ' Youku ': {},}, ' on the ground ': {' Baidu ': {},},}, ' Changping ': {        ' Shahe ': {' old boy ': {}, ' Beihang ': {},}, ' Tian Tong Yuan ': {}, ' Huilongguan ': {},            }, ' Chaoyang ': {}, ' Dongcheng ': {},}, ' Shanghai ': {' Minhang ': {' People's Square ': {' Fried chicken Shop ': {} }}, ' Zhabei ': {' rail war ': {' Ctrip ': {}}}, ' Pudong ': {},}, ' Shandong ': { },} Requirements: You can choose to go to each submenu from any level back to the previous layer you can exit the program from any level required new knowledge points: List, dictionary 
Reference Code is as follows:
 # coding:utf-8 
#!/usr/bin/env python3
Menu = {
' Beijing ': {
' Haidian ': {
' five crossings ': {
' Soho ': {},
' NetEase ': {},
' Google ': {}
},
' Zhongguancun ': { ' Iqiyi art ': {},
' Autohome ': {},
' Youku ': {},
},
' Land ': {
' Baidu ': {},
},
},
' Changping ': {
' Shahe ': {
' Old boy ': {},
' Beihang ': {},
},
' Tian Tong Yuan ': {},
' Huilongguan ': {},
} ,
' Chaoyang ': {},
' Dongcheng ': {},
},
' Shanghai ': {
' Minhang ': {
' People's Square ': {
' Fried Chicken Shop ': {}
}
},
' Zhabei ': {
' train war ': {
' Ctrip ': {}
}
},
' Pudong ': {},
},
' Shandong ': {},
}
#递归方式实现
def show_menu (CH):
For s in CH:
Print (s)
Print (' Return/exit ')
p = input (' You select Yes ')
if p = = ' exit ':
Exit ()
elif p = = ' return ':
Return
Else
If p in Ch:
Show_menu (Ch[p])
Show_menu (CH)
Show_menu (Menu)

Three-level menu Python notation (recursive notation)

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.