V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2013-08-09 15:07:43 +08:00 · 2167 次点击
    这是一个创建于 3934 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    1970-01-01 08:00:00 +08:00
    timonwong
        1
    timonwong  
       2013-08-09 15:25:25 +08:00
    list是mutable的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2251 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 01:22 · PVG 09:22 · LAX 18:22 · JFK 21:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.