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

Python list 根据百分比切成若干个。

  •  
  •   csdreamdong · Jun 21, 2017 · 3881 views
    This topic created in 3394 days ago, the information mentioned may be changed or developed.

    有个 200 万左右量的 list。

    这个数量级。虽然我知道不该用 list。

    但。。。继续主题。有啥优雅点方法没。

    非要自己算百分比然后冒号去切片么?

    python 有啥黑科技。是根据百分比自动切 list 的

    7 replies  •  2017-06-22 10:23:12 +08:00
    herozhang
        1
    herozhang  
       Jun 21, 2017 via iPhone
    不是根据百分比计算下标,然后根据下标取数据么
    Valyrian
        2
    Valyrian  
       Jun 21, 2017
    不要真切了吧。。太慢了。计算每个分段的起点终点吧
    Michaelssss
        3
    Michaelssss  
       Jun 21, 2017
    再黑的科技。。最终落到实处也是要计算百分比落脚的 int 值
    mooncakejs
        4
    mooncakejs  
       Jun 21, 2017
    最好的办法是写一个 proxy list 根据冒号生成 offset 访问的 时候 index = offset+index
    BiggerLonger
        5
    BiggerLonger  
       Jun 21, 2017
    沒有, 應該用 itertools islice
    ruoyu0088
        6
    ruoyu0088  
       Jun 21, 2017
    列表里面保存的是什么?
    NoAnyLove
        7
    NoAnyLove  
       Jun 22, 2017
    直接用方括号切片,如果我没记错的话,是一定会产生一个新的 copy 的。。。。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   758 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 20:19 · PVG 04:19 · LAX 13:19 · JFK 16:19
    ♥ Do have faith in what you're doing.