A dict-like container that allows multiple keys to address the same value.
Project description
Multi-Lookup-Dict
A Dict-like container that allows multiple keys to address the same value.
>>> d = MultiLookupDict()
>>> d["a_key"] = "some_value"
>>> d.map_key("a_key", "another_key") # Make "another_key" an alias of "a_key"
Implemented as two dicts:
MultiLookupDict._data
holds the 'canonical key' and valueMultiLookupDict._key_to_canonical_map
maps 'alias keys' onto canonical keys. (Canonical keys are mapped to themselves in this dict)
Externally, all keys (canonical and alias) are treated identically,
and all refer to the same value, unless a key is reassigned individually with a new value using __setitem__
Methods
__setitem__
Sets a key to the value. If a (non-string) iterable is provided
as key, each key will be assigned the value.
__getitem__
[As with standard Python dict
]
map_key
Assign the value of one key to another key. Both keys
now point to the same value.
keys
Returns all keys in MultiLookupDict. Returned keys refer to same or different objects.
all_keys
[Same as keys
]
values
[Same as values
]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for multilookupdict-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7efcef43939c25c91e39360c47ad58ac63e4a97224b9098ded6bb85d7e3b97d |
|
MD5 | ec3f0027a24e28e3bb84491f43356dfa |
|
BLAKE2b-256 | 2fece8baa572dd44e1b4776a77fb4b4476fa1ce0b332bcd7b8826d8e33fbcacb |