A dict that works with both hashable and non-hashable keys
Project description
All Purpose Dict
Note: This document is best viewed on github. Pypi's headers are all caps which presents inaccurate information"
Table of Contents
What is it?
- A dict which doesn't require hashable keys
Why create it?
-
I often have a need to store non-hashable keys in a dict. For example storing a dict as a key isn't possible with the builtin dict.
# doesn't work someDict = { "key": "value" } anotherDict = { someDict: "anotherValue" }
Simple usage
from all_purpose_dict import ApDict
someDict = { "key": "value" }
anotherDict = ApDict([(someDict, "anotherValue")])
print(someDict in anotherDict) # prints True
See Also
Api
Note: This api is young and subject to change quite a bit. There also may be functionality present in the builtin dict which ApDict doesn't cover. I'm willing to add it so please just raise a github issue or PR with details.
class ApDict([a list of pairs])
- 'pairs' may be either a list or tuple with a length of 2
- all methods return
self
unless specified otherwise - iterates in the order of insertion
- views are not implemented because I don't have a need for them. Instead I
expose
keysIterator
andvaluesIterator
. If you need views then raise a github issue. - the internal methods implemented are
- __contains__
- __delitem__
- __getitem__
- __iter__
- __len__
- __setitem__
clear()
delete(key)
- a function alternative to
del aDict[key]
get(key) => value
- a function alternative to
val = aDict[key]
has(key) => bool
- a function alternative to
key in aDict
keysIterator() => ApDictKeysIterator
set(key, value)
- a function alternative to
aDict[key] = val
valuesIterator() => ApDictValuesIterator
Test
#
# you must have poetry installed
#
$ poetry shell
$ poetry install
$ python runTests.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
all_purpose_dict-0.1.1.tar.gz
(9.4 kB
view hashes)
Built Distribution
Close
Hashes for all_purpose_dict-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5946a956f6289862f20cc1be7d307ad525d9c6a79a21ea55006e7744e5aa375 |
|
MD5 | 5e686153460679103aad0b40fd2b73d3 |
|
BLAKE2b-256 | b37345439054d96d04e860c317c98d2ba1d78eff007d6ba55212ffda6b5a8ab7 |