frozendict
¶
Provides an immutable dictionary implementation.
This module implements a frozen (immutable) dictionary class that can be used where hashable dictionaries are needed, such as in sets or as keys in other dictionaries. Once created, a FrozenDict cannot be modified.
Classes:
Name | Description |
---|---|
FrozenDict |
An immutable dictionary implementation. |
Functions:
Name | Description |
---|---|
exclude |
Exclude the keys of a dictionary. |
merge |
Merge multiple dictionaries into a single dictionary. |
rekey |
Rekey the keys of a dictionary. |
FrozenDict
¶
FrozenDict(data: dict[K, V])
Bases: Mapping[K, V]
, Generic[K, V]
An immutable dictionary implementation.
FrozenDict provides a hashable, immutable view of a dictionary. It implements the Mapping interface but does not allow modification after creation. This makes it suitable for use as dictionary keys or in sets where mutability would cause issues.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict[K, V]
|
Dictionary to create a frozen copy of |
required |
exclude
¶
exclude(
maps: Mapping[Any, Any], exclude: Iterable[Any]
) -> FrozenDict[Any, Any]
Exclude the keys of a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
maps
|
Mapping[Any, Any]
|
Dictionary to exclude from |
required |
exclude
|
Iterable[Any]
|
Keys to exclude |
required |
Returns:
Type | Description |
---|---|
FrozenDict[Any, Any]
|
A new dictionary with the keys excluded |
merge
¶
merge(
*maps: Mapping[Any, Any] | None
) -> FrozenDict[Any, Any]
Merge multiple dictionaries into a single dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*maps
|
Mapping[Any, Any] | None
|
Dictionaries to merge |
()
|
Returns:
Type | Description |
---|---|
FrozenDict[Any, Any]
|
A new dictionary containing the merged contents of all input dictionaries |
rekey
¶
rekey(
maps: Mapping[Any, Any], rekey: Mapping[Any, Any]
) -> FrozenDict[Any, Any]
Rekey the keys of a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
maps
|
Mapping[Any, Any]
|
Dictionary to rekey |
required |
rekey
|
Mapping[Any, Any]
|
Mapping of old keys to new keys |
required |
Returns:
Type | Description |
---|---|
FrozenDict[Any, Any]
|
A new dictionary with the keys remapped |