- Python Data Structures and Algorithms
- Benjamin Baka
- 103字
- 2021-07-09 19:45:03
Immutable sets
Python has an immutable set type called frozenset. It works pretty much exactly like set apart from not allowing methods or operations that change values such as the add() or clear() methods. There are several ways that this immutability can be useful. For example, since normal sets are mutable and therefore not hashable, they cannot be used as members of other sets. The frozenset, on the other hand, is immutable and therefore able to be used as a member of a set:

Also the immutable property of frozenset means we can use it for a key to a dictionary, for example:

推薦閱讀
- MySQL數(shù)據(jù)庫管理實戰(zhàn)
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- Computer Vision for the Web
- Learning Apex Programming
- Android開發(fā)精要
- Java面向?qū)ο筌浖_發(fā)
- Troubleshooting PostgreSQL
- 劍指MySQL:架構(gòu)、調(diào)優(yōu)與運維
- Node Cookbook(Second Edition)
- IDA Pro權(quán)威指南(第2版)
- C++程序設(shè)計教程(第2版)
- Application Development with Swift
- Qt 4開發(fā)實踐
- Get Your Hands Dirty on Clean Architecture
- Learning Redis