推荐学习书目
› 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
yakczh
V2EX  ›  Python

关于尾递归的函数在循环中的问题

  •  
  •   yakczh · Aug 9, 2013 · 2985 views
    This topic created in 4799 days ago, the information mentioned may be changed or developed.
    def cat(para,x):
    if len(x)==0:
    return para
    prefix=x.pop()
    para=prefix+para
    return cat(para,x)



    b=['http',":","//","www",".baidu.com"]
    hrefs=['/t20120705_1887040.html', '/t20120608_1846662.html']
    for url in hrefs:
    c=[]
    c=b
    print(cat(url,c))

    本来是将每个链接用尾递归函数处理一遍,但是第二条纪录以后, b就已经变为空了
    1 replies  •  1970-01-01 08:00:00 +08:00
    timonwong
        1
    timonwong  
       Aug 9, 2013
    list是mutable的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   941 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:15 · PVG 03:15 · LAX 12:15 · JFK 15:15
    ♥ Do have faith in what you're doing.