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
bestehen
V2EX  ›  Python

Python 中的列表 算法问题

  •  
  •   bestehen · Jul 26, 2018 · 1663 views
    This topic created in 2832 days ago, the information mentioned may be changed or developed.

    ['/N/98445.html', '/N/98439.html', '/HomeV2/Banner/Records?model=A1&name=A1&url=https%3A%2F%2Fwww.jiemodui.com%2FKe%2F97539.html%3Ffrom%3Djmd004&flag=3a6f8321cf5ca56b13fd4a40a9474246', '/N/98441.html', '/N/98436.html', '/N/98435.html', '/N/98433.html', '/N/98434.html', '/HomeV2/Banner/Records?model=A3&name=A3&url=https%3A%2F%2Fwww.jiemodui.com%2FA%2F98137%3F%3Dxxl3&flag=90e994d56cd13c6b3201012bc988873a', '/N/98432.html', '/N/98431.html', '/N/98430.html', '/N/98429.html', '/N/98427.html', '/N/98426.html', '/N/98421.html', '/N/98416.html', '/N/98420.html', '/N/98407.html', '/N/98419.html', '/N/98411.html', '/N/98406.html']

    这里我想保留 /N/98445.html 类似的格式,把 很长的 /HomeV2 那两个很长的从列表中删除,我想到的办法就是遇到这个字符串 pass 然后 重新构造一个列表添加,因为可能这个带 /HomeV2 字符串不在这个位置 有没有不需要重新构造一个列表直接在原来的列表删除这两个有 /HomeV2 的长字符串

    xpresslink
        1
    xpresslink  
       Jul 27, 2018
    new_list = [element for element in old_list if element.startswith('/N/')]
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   952 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 20:54 · PVG 04:54 · LAX 13:54 · JFK 16:54
    ♥ Do have faith in what you're doing.