- 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:

推薦閱讀
- 手機安全和可信應用開發指南:TrustZone與OP-TEE技術詳解
- Learning PostgreSQL
- Dynamics 365 Application Development
- Learning RxJava
- UML 基礎與 Rose 建模案例(第3版)
- 運用后端技術處理業務邏輯(藍橋杯軟件大賽培訓教材-Java方向)
- Microsoft Azure Storage Essentials
- PHP從入門到精通(第4版)(軟件開發視頻大講堂)
- 新一代SDN:VMware NSX 網絡原理與實踐
- Hands-On GUI Programming with C++ and Qt5
- UI設計全書(全彩)
- R語言數據可視化:科技圖表繪制
- C編程技巧:117個問題解決方案示例
- 單片機原理及應用技術
- 零基礎輕松學C++:青少年趣味編程(全彩版)