推荐学习书目
› 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 · 6207 views
    This topic created in 4220 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
    futursolo
    Apr 18, 2015❤️1
    1
    如果你指的是字典(Dict),那么应该没有顺序(顺序是随机的,正反向都无所谓).
    如果你指的是列表,可以这样操作:
    for item in (list[::-1])

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

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