zoukankan      html  css  js  c++  java
  • 三级菜单

    menu = {
        '大一':{
            '学科':{
                'c语言':{},
                '物联网概论':{},
                '初识python': {},
                '操作系统':{}
            },
            '娱乐':{
                '运动会':{},
                '实验室':{},
                '学生会':{}
            }
        },
        '大二': {
            '课程': {
                '计算机组成原理': {},
                '数据结构': {},
                '单片机': {},
                '计算机网络':{}
            },
            '兼职':{
                '家教':{},
                '进厂':{},
                '服务员':{}
            }
        },
        '大三': {
            '自学': {
                'python': {},
                '数据结构': {},
                '前端': {},
                '数据库':{}
            },
            '经历':{
                '找实习':{},
                '实习':{}
            }
        }
    }
    
    # 方法一:用递归的方式
    def ThreeMenu(dic):
        while 1:
            for key in dic:print(key)
            key = input('>>>').strip()
            if key == 'b' or key == 'q':return key
            elif key in dic.keys() and dic[key]:
                res = ThreeMenu(dic[key])
                if res == 'q': return 'q'
            elif (not dic.get(key)) or (not dic[key]):
                continue
    ThreeMenu(menu)
    
    
    #方法二:用堆栈的方式
    l = [menu]
    while l:
        for key in l[-1]:print(key)
        k = input('input>>').strip()   # 北京
        if k in l[-1].keys() and l[-1][k]:
            l.append(l[-1][k])
        elif k == 'b':l.pop()
        elif k == 'q':break
  • 相关阅读:
    JVM Inline
    Lattice
    编译技术
    sql-server-on-linux
    concurrency 方面的books
    Linux debugger lldb
    javaperformanceoptimization
    Understanding The Linux Virtual Memory Manager
    web performance tu ning
    linux io architecture
  • 原文地址:https://www.cnblogs.com/twinkle-/p/10546233.html
Copyright © 2011-2022 走看看