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

请教一个字符串分割的问题

  •  
  •   kenneth · Nov 28, 2014 · 2474 views
    This topic created in 4182 days ago, the information mentioned may be changed or developed.
    例如
    url='http://www.test.com/a=1&b=2&c=3'
    print url.split('&')[0]

    我希望得到
    url='http://www.test.com/a=1&b=2

    也就是按最后一个&分
    要怎么写?
    3 replies    2014-12-02 02:35:21 +08:00
    whywhywhy
        1
    whywhywhy  
       Nov 29, 2014
    url='http://www.test.com/a=1&b=2&c=3'
    print url.split('&c=')[0]
    irainy
        2
    irainy  
       Nov 29, 2014
    '&'.join(url.split('&')[:-1])
    KentY
        3
    KentY  
       Dec 2, 2014 via iPhone
    手机cp/paste不方便,你就re.sub(u'&[^&]*$','',url)就好了吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3033 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 15:11 · PVG 23:11 · LAX 08:11 · JFK 11:11
    ♥ Do have faith in what you're doing.