Difference between tuples and frozensets in Python(Python中元组和冻结集之间的区别)
问题描述
我正在使用 The Quick Python Book 学习 Python 3,作者在其中谈到了frozensets,并指出由于 set 是可变的,因此不可散列,因此不适合作为字典键,因此引入了它们的 freeze 对应项.除了元组是有序数据结构而frozenset(或更一般地说是集合)是无序的明显区别之外,元组和frozenset之间还有其他区别吗?
I'm learning Python 3 using The Quick Python Book, where the author talks about frozensets, stating that since sets are mutable and hence unhashable, thereby becoming unfit for being dictionary keys, their frozen counterparts were introduced. Other than the obvious difference that a tuple is an ordered data structure while frozenset, or more generally a set, is unordered, are there any other differences between a tuple and a frozenset?
推荐答案
tuples
是不可变的lists
,frozensets
是不可变的sets
.
tuples
are immutable lists
, frozensets
are immutable sets
.
tuples
确实是对象的有序集合,但它们可以包含重复和不可散列的对象,并且具有切片功能
tuples
are indeed an ordered collection of objects, but they can contain duplicates and unhashable objects, and have slice functionality
frozensets
没有被索引,但你有 sets
的功能 - O(1) 元素查找,以及联合和交集等功能.它们也不能包含重复项,就像它们的可变对应项一样.
frozensets
aren't indexed, but you have the functionality of sets
- O(1) element lookups, and functionality such as unions and intersections. They also can't contain duplicates, like their mutable counterparts.
这篇关于Python中元组和冻结集之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python中元组和冻结集之间的区别


- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01