Planet Python
Follow
Rodrigo Girão Serrão: frozendict built-in
Python 3.15 introduces a new immutable dictionary type called frozendict. You create frozendicts using the built-in frozendict() constructor, not curly braces. This ensures that the dictionary's contents cannot be changed after creation. You can access elements within a frozendict using standard dictionary key access. Iterating through a frozendict's keys, values, or items is also supported. It is recommended to use frozendict for dictionaries that should not be modified. This immutability makes frozendicts hashable, a key characteristic. Understanding hashability is important for their use. The article series celebrates Python 3.15 features with daily explanations. The author plans to cover new features over 15 business days with examples.