dict_digger
Digs into Dicts
Useful syntax for digging into nested dictionaries, lists and tuples, and removes the need to check if a key or index exists, or handling of KeyError or IndexError
Installation
$ pip install dict_digger
Usage
import dict_digger
h = {
'a': {
'b': 'tuna',
'c': 'fish'
},
'b': {}
}
result = dict_digger.dig(h, 'a','b')
print result # prints 'tuna'
result = dict_digger.dig(h, 'c','a')
print result # prints None
# Important!! Does not through an error, just returns None
#but if you like
result = dict_digger.dig(h, 'c','a', fail=True)
# raises a KeyError
# also support complex objects so ...
complex = {
'a': {
['tuna','fish']
},
'b': {}
}
result = dict_digger.dig(complex, 'a',0)
print result #prints tuna
Alternatives
try:
result = h['c']['a']
except KeyError:
result = None
Testing
We are using nose
$ nosetests
Metadata
Release files for dict_digger 0.2.1
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 | |
|---|---|---|---|---|
| dict_digger-0.2.1.tar.gz | 1.6 kB | Without provenance | Details |
Release files / dict_digger-0.2.1.tar.gz
| Download URL | dict_digger-0.2.1.tar.gz |
|---|---|
| Size | 1.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85db80169b93bfa3df55f1f111bc2ca695a48e7f4cbcb09aaee37df52094efdd
|
|
BLAKE2b-256 checksum How to use checksums |
778621a269637c44bbcd0a6b1cf8e2e72e56ebaf70e354cce4df852089a907ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for dict_digger 0.2.1
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.