Skip to main content

A tool for iterating dictionaries as trees and printing all leaf nodes at some path

Project description

Usage

Takes a dict, and a path delimited with slashes like A/B/C/D, and returns a list of all leaves at all trajectories dict[A][B][C][D]

If the path is an empty string, returns the original dict

Each non-leaf node can be either a dictionary or list of objects including dictionaries.

Each leaf node can be an arbitrary object.

Non-leaf inner nodes that are not dictionaries are ignored.

Motivation

Jsons sometimes have many levels and are a pain to parse.

This package was motivated by the pain in iterating dicts I received from calling simplejson on objects returned from various Twitter API calls. The API objects I had to parse had quadruple level nested dictionaries, and when I was playing around with the data, I wanted to be able to query different levels to see if the data was interesting.

Then I found out nothing in the Python language natively supports querying nested dicts when they may or may not exist: http://stackoverflow.com/questions/26979046/python-check-multi-level-dict-key-existence

Examples

See https://github.com/tommyjcarpenter/dictsearch

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dictsearch-1.2.tar.gz (1.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page