set函数的返回值是如何组织的? [英] How is the return value of the set function organized?

查看:66
本文介绍了set函数的返回值是如何组织的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:我使用了 set() 并返回 [3, 14, 6]

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])

我的问题是 set 函数如何组织它的值输出.如果我们考虑一下,3 是列表中的第一个数字,6 是第二个数字,那么它应该输出 [3,6,14] 吗?

My question is how is the set function organizes it values output. If we think about this, 3 is the first number and 6 is the second on the list, so should it output [3,6,14] instead?

推荐答案

集合是无序的.来自文档:

作为无序集合,集合不记录元素位置或插入顺序.

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.

这篇关于set函数的返回值是如何组织的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆