How is the return value of the set function organized?

前端 未结 2 1776
不思量自难忘°
不思量自难忘° 2021-01-17 02:45

Here is my code: i used set() and it return [3, 14, 6]

items = [3, 6, 3, 3, 14]
set(items)
>>> set([3,14,6])

My question is how is

2条回答
  •  被撕碎了的回忆
    2021-01-17 03:32

    Sets are unordered. From the documentation:

    Being an unordered collection, sets do not record element position or order of insertion.

    Like dictionaries, the ordering is based on the hashes of the stored keys. You cannot rely on this apparent ordering to remain stable.

    If you are interested in the underlying data model, the underlying data structure is called a Hash Table, but in sets only keys are stored, values are left empty.

提交回复
热议问题