Multi-Key Dictionary

2.0.3 · maintenance · verified Thu Apr 09

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

Install

Imports

Quickstart

This example demonstrates how to create a multi-key dictionary, assign a value using multiple keys, access the value via any of its keys, update the value through one key (affecting all associated keys), and delete the value through one key (making it inaccessible via others).

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}")

view raw JSON →