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

list 里边按 index 插入 list 并展开?有啥好方法吗

  •  
  •   css3 · Aug 6, 2019 · 2512 views
    This topic created in 2662 days ago, the information mentioned may be changed or developed.

    想把一个 list 插入到另一个 list 的倒数第二位并展开。有什么简单的办法不

    a = [1,2,3,4]
    
    b = ["a", "b"]
    
    c = [1,2,3,"a","b",4] #如何让 c 等于这样?
    
    6 replies  •  2019-08-07 16:29:14 +08:00
    zhusimaji
    zhusimaji
    Aug 6, 2019 via Android
    1
    a[:-1]+b+a[-1]
    cassidyhere
    cassidyhere
    Aug 6, 2019
    2
    a[-2:-1] = b
    Abirdcfly
    Abirdcfly
    Aug 7, 2019
    3
    c = a[:-1] + b + a[-1]
    或者
    a[-1:0]=b
    xpresslink
    xpresslink
    Aug 7, 2019
    4
    二楼+100086
    sladesha
    sladesha
    Aug 7, 2019
    5
    a[-1:-1] = b 即可
    hongda0812
    hongda0812
    Aug 7, 2019
    6
    也可取出 list 遍历也行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4680 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 01:53 · PVG 09:53 · LAX 17:53 · JFK 20:53
    ♥ Do have faith in what you're doing.