Skip to content

Instantly share code, notes, and snippets.

@markrwilliams
Created October 13, 2013 02:19
Show Gist options
  • Save markrwilliams/6957361 to your computer and use it in GitHub Desktop.
Save markrwilliams/6957361 to your computer and use it in GitHub Desktop.
def collect_keys(d):
if not isinstance(d, dict):
return []
level = d.keys()
for k, v in d.items():
level.extend('%s.%s' % (k, c) for c in collect_keys(v))
return level
def analyze(paths):
survey = {}
for p in paths:
survey[p] = survey.setdefault(p, 0) + 1
return survey
def survey_dicts(lod):
return analyze([path
for d in lod
for path in collect_keys(d)])
lod = [{'d': {'c': 1, 'e': 2}, 'a': 3},
{'d': {'c': 1, 'f': 1}},
{'a': 4}]
print survey_dicts(lod)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment