ksuit.utils.bidict¶
Attributes¶
Classes¶
A bidirectional dictionary that allows for two-way lookups. |
Module Contents¶
- ksuit.utils.bidict.KT¶
- ksuit.utils.bidict.VT¶
- class ksuit.utils.bidict.Bidict(forward=None)¶
A bidirectional dictionary that allows for two-way lookups.
This dictionary allows you to get values by key and keys by value.
Create a new Bidict.
This constructor takes two optional dictionaries for forward and backward mapping. At least one of them must be not None.
- Parameters:
forward (dict[KT, VT] | None) – A dictionary for forward mapping.
backward – A dictionary for backward mapping.
- get_value_by_key(key)¶
Get a value by key.
- Parameters:
key (KT) – The key to look up.
- Return type:
VT
- get_key_by_value(value)¶
Get a key by value. :param key: The value to look up.
- Parameters:
value (VT)
- Return type:
KT
- set(key, value)¶
Add a new key-value pair.
- Parameters:
key (KT) – The key to add.
value (VT) – The value to associate with the key.
- Return type:
None