推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
zmrenwu
V2EX  ›  Python

如何理解这段代码(一行代码实现一个树结构字典)?

  •  
  •   zmrenwu · Nov 7, 2016 · 2536 views
    This topic created in 3610 days ago, the information mentioned may be changed or developed.
    from collection import defaultdict
    
    tree = lambda: defaultdict(tree)
    

    运行:

    tree['foo']['bar'] = 'span'
    

    结果:

    {'foo', {'bar': 'span'}}
    

    无法理解 lambda 函数里面的递归,可否解释一下代码究竟是怎么样执行的?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   981 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 18:34 · PVG 02:34 · LAX 11:34 · JFK 14:34
    ♥ Do have faith in what you're doing.