All Purpose Dict
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
selfunless specified otherwise - iterates in the order of insertion
- views are not implemented because I don't have a need for them. Instead I
expose
keysIteratorandvaluesIterator. 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, default=None) => value
- get the value for key if key is in the dictionary, else default.
- note: this never raises a KeyError.
has(key) => bool
- a function alternative to
key in aDict
getKeysIterator() => ApDictKeysIterator
set(key, value)
- a function alternative to
aDict[key] = val
getValuesIterator() => ApDictValuesIterator
Test
#
# you must have poetry installed
#
$ poetry shell
$ poetry install
$ python runTests.py
Metadata
Release files for all-purpose-dict 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| all_purpose_dict-0.2.4.tar.gz | 178.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| all_purpose_dict-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 388.4 kB
Release files / all_purpose_dict-0.2.4.tar.gz
| Download URL | all_purpose_dict-0.2.4.tar.gz |
|---|---|
| Size | 178.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1ca3b4a4ad4311096b38ed9545b463eeaf5f4ed09735a27e8ca20b20a1ca401
|
|
BLAKE2b-256 checksum How to use checksums |
fd1a830cecdfc94f7ad0441b7941cadf41354f305be79e282e4cfd9364489a6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH
|
Release files / all_purpose_dict-0.2.4-py3-none-any.whl
| Download URL | all_purpose_dict-0.2.4-py3-none-any.whl |
|---|---|
| Size | 209.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aadeb0f634546ff3f92b4e85d30a76400c9c241bbc8a68f6e2aed96e32e380de
|
|
BLAKE2b-256 checksum How to use checksums |
11e1cbcffe53b7cc176b824f0644e3d43490307deaf251b47cc8e4fd5a4d7467
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.15 CPython/3.7.3 Linux/5.1.2-arch1-1-ARCH
|
Security for all-purpose-dict 0.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.