推荐学习书目
› 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 · 5128 views
    This topic created in 2940 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
        1
    yemoluo  
       Sep 6, 2018
    楼主多试一试几次

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

    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
        3
    drawstar  
       Jan 2, 2020
    @PythonAnswer 从文档能看出啥?无序的?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   981 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 18:47 · PVG 02:47 · LAX 11:47 · JFK 14:47
    ♥ Do have faith in what you're doing.