Multi-Key Dictionary
multi-key-dict (version 2.0.3) is a Python library that provides a dictionary implementation allowing multiple distinct keys to refer to the same single value. It extends the standard dictionary interface to enable access, update, and deletion of elements via any of its associated keys. The library appears to be in maintenance mode, with its last release in 2015.
Warnings
- gotcha This library enables multiple *keys* to point to a *single value*. It is not designed for a single key to hold multiple values (like the `multidict` library does for HTTP headers). Attempting to store multiple values for one key will overwrite previous values.
- gotcha Updating a value using any of its associated keys will change the single underlying value. All other keys linked to that original value will then reflect the new updated value.
- gotcha Deleting an item via one of its associated keys will remove the underlying value entirely. Consequently, the value will no longer be accessible through any other key that was previously linked to it, resulting in a KeyError.
- deprecated The latest release of multi-key-dict (2.0.3) was published in 2015, indicating a very slow development or maintenance-only cadence. While functional, it might not receive frequent updates or new features.
Install
-
pip install multi-key-dict
Imports
- multi_key_dict
from multi_key_dict import multi_key_dict
Quickstart
from multi_key_dict import multi_key_dict
k = multi_key_dict()
k[1000, 'kilo', 'k'] = 'kilo (x1000)'
print(f"Value for key 1000: {k[1000]}")
print(f"Value for key 'k': {k['k']}")
k['kilo'] = 'kilo'
print(f"Updated value for key 1000: {k[1000]}")
del k[1000]
# Accessing any other key will now raise a KeyError as the value is deleted
try:
print(k['kilo'])
except KeyError as e:
print(f"Accessing 'kilo' after deleting by 1000: {e}")