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

求问, jinjia2 逆向的遍历

  •  
  •   lixia625 · Apr 18, 2015 · 6075 views
    This topic created in 4177 days ago, the information mentioned may be changed or developed.

    for item in dict是正向遍历的话,
    有没有类似的方便的方法可以倒序的循环?

    4 replies  •  2015-04-19 09:24:40 +08:00
    futursolo
        1
    futursolo  
       Apr 18, 2015   ❤️ 1
    如果你指的是字典(Dict),那么应该没有顺序(顺序是随机的,正反向都无所谓).
    如果你指的是列表,可以这样操作:
    for item in (list[::-1])

    如果你指的是有序字典,那么这样操作:
    for item in (list(dict.keys())[::-1])
    yuanji
        2
    yuanji  
       Apr 18, 2015 via iPhone   ❤️ 1
    for i in items | reverse

    这样?
    lixia625
        3
    lixia625  
    OP
       Apr 18, 2015
    @jyjmrlk 正是我想要的答案,同时也感谢@futursolo
    vansje
        4
    vansje  
       Apr 19, 2015
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2452 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 06:19 · PVG 14:19 · LAX 23:19 · JFK 02:19
    ♥ Do have faith in what you're doing.