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
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 | |
|---|---|---|---|
| dict_digger-0.2.1.tar.gz | 1.6 kB | 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 |