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

python3 中 set 进行列表去重时 为什么会自动进行排序(升序)

  •  
  •   mili8908 · Sep 6, 2018 · 5256 views
    This topic created in 2990 days ago, the information mentioned may be changed or developed.
    In [35]: set([1, 3, 8, -2, 99, 98, 77, 1, 5, 3, 77, 12])
    Out[35]: {-2, 1, 3, 5, 8, 12, 77, 98, 99}


    In [31]: o = [2,5,1,2,4,6,0,33,5.4,6.4]

    In [32]: c = set(o)

    In [33]: c
    Out[33]: {0, 1, 2, 4, 5, 5.4, 6, 6.4, 33}
    3 replies  •  2020-01-02 11:13:19 +08:00
    yemoluo
    yemoluo
    Sep 6, 2018
    1
    楼主多试一试几次

    即使你看到了十次都是有序的,也不要相信,`set` 是无序的 `set` 是无序的 `set` 是无序的
    PythonAnswer
    PythonAnswer
    Sep 6, 2018
    2
    楼主多看文档

    5.4. Sets

    Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.

    Curly braces or the set() function can be used to create sets. Note: to create an empty set you have to use set(), not {}; the latter creates an empty dictionary, a data structure that we discuss in the next section.
    drawstar
    drawstar
    Jan 2, 2020
    3
    @PythonAnswer 从文档能看出啥?无序的?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2125 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 07:51 · PVG 15:51 · LAX 23:51 · JFK 02:51
    ♥ Do have faith in what you're doing.