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

推薦閱讀
- Data Analysis with Stata
- 人人都懂設計模式:從生活中領悟設計模式(Python實現)
- FLL+WRO樂高機器人競賽教程:機械、巡線與PID
- HDInsight Essentials(Second Edition)
- Apache Kafka Quick Start Guide
- Python圖形化編程(微課版)
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- Hands-On Neural Network Programming with C#
- 數據科學中的實用統計學(第2版)
- 深度學習入門:基于Python的理論與實現
- Get Your Hands Dirty on Clean Architecture
- Flink入門與實戰
- React.js實戰
- C語言程序設計實驗指導與習題精解
- 零基礎入門學習C語言:帶你學C帶你飛