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

字典中键值顺序发生变化

  •  
  •   wildfarmer · Mar 4, 2015 · 3018 views
    This topic created in 4082 days ago, the information mentioned may be changed or developed.
    >>> d={'first':'1', 'second':'2', 'third':'3'}
    >>> d
    {'second': '2', 'third': '3', 'first': '1'}
    

    为什么输出中,字典中键值的顺序发生变化了?
    求教各位

    3 replies    2015-03-04 20:12:12 +08:00
    messense
        1
    messense  
       Mar 4, 2015   ❤️ 1
    字典是无序的,希望有序的话可以使用 collections.OrderedDict

    https://docs.python.org/2.7/library/collections.html#collections.OrderedDict
    pljhonglu
        2
    pljhonglu  
       Mar 4, 2015   ❤️ 1
    字典是哈希存储,本身就是无序的~
    wildfarmer
        3
    wildfarmer  
    OP
       Mar 4, 2015
    @messense @pljhonglu 谢谢二位,初学python :)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5618 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 07:32 · PVG 15:32 · LAX 00:32 · JFK 03:32
    ♥ Do have faith in what you're doing.