Skip to main content

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)

Source distribution for dict_digger 0.2.1
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

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page