V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 2663 views
    This topic created in 4645 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   ·   Solana   ·   1000 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:16 · PVG 03:16 · LAX 12:16 · JFK 15:16
    ♥ Do have faith in what you're doing.